3

I have /var/lib/home folder in my docker container and I want to access this folder contents from my computer.

How to map this folder to host?

I'd like this folder to be writable also during usage.

1
  • You can make a persist volume in your container and the persist volume could be in your host. You can follow this link to do the persist volume.
    – Charles Xu
    Aug 1, 2018 at 7:31

1 Answer 1

1

You can make use of bind mounts

When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its full or relative path on the host machine. By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.

docker run -d \
  -it \
  --name bind--mount-test \
  --mount type=bind,source=/path/to/host/directory/,target=/var/lib/home \
  <docker image name>

bear in mind the first time when the container is created, /var/lib/home will be mounted from the host and not vice-versa

1
  • "If you bind-mount a directory into a non-empty directory on the container, the directory's existing contents are obscured by the bind mount." superuser.com/questions/1344863/…
    – Akito
    Oct 15, 2023 at 11:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .