2

I'm trying to copy the folder and contents from a source to a Docker container using an image. I built the image from my Dockerfile.

RUN useradd -m -s /bin/bash user1 && \
ln -s /foo /home/user1/foo

RUN mkdir /foo && && chown -R user1:user1 /foo
VOLUME /foo

After I build the Docker image, I run these commands to create a container.

docker run -it
--name container_name \
--mount "type=bind,source=$(pwd)/$FOLDER/container_foo,destination=/foo/" \
dockerimage:tag

The files from the source folder /foo isn't in the /container_foo. I checked by doing docker exec -it container_ID /bin/bash and confirmed that the files aren't there.

EDIT :

I just found out that mount only goes one way, exposing local host files/folder to the docker container. It doesn't copy the files inside of the docker container to the local folder when mounting. I removed creating the /foo directory from RUN and VOLUME. Instead I did this in the Dockerfile.

COPY --chown=user1:user1 foo/ foo/

And I was able to copy the files from source. Now I just need to copy it from there to container_foo when doing the docker run ... command.

Dennis
  • 21
  • 3
  • what are you trying to do? do you want files from `container_foo` in docker under `/foo`? – Shahriar Jul 10 '20 at 14:47
  • Actually I want the other way around. I want the files from `/foo` to `container_foo`. I just discovered now that `mount` can't do that as it only goes one way, exposing local host files/folder to the docker container. – Dennis Jul 10 '20 at 22:21
  • did you try `--volume`? – Shahriar Jul 10 '20 at 22:57
  • Does this answer your question? [Copying files from Docker container to host](https://stackoverflow.com/questions/22049212/copying-files-from-docker-container-to-host) – Shahriar Jul 10 '20 at 23:04

0 Answers0