Joschi
Joschi

Reputation: 2128

Docker - access existing container files on host machine

I have a docker container which has some data in let's say /opt/files. File A and B. How can I start that container and access these files on my host machine?

I'm using Docker for Windows (Hyper-V). When i start the container with:

docker run -it -v C:/tmp:/opt/files myImage

I see an empty folder on my windows machine and inside of the container. Any new files I create there are of course reflected on both sides but how can I access files that are already in the container (e.g. because they're added in the Dockerfile)?

Upvotes: 1

Views: 3206

Answers (2)

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

You can't share from inside container to host. There are two ways to do it

Copy the files from container

docker cp <containerid>:<file_path_inside_container> localpath

Share a folder other than the one where files will be generated

docker run -it -v C:/tmp:/opt/files_temp myImage

Then you get inside the container copy files from /opt/files to /opt/files_temp

Upvotes: 1

Guillaume Husta
Guillaume Husta

Reputation: 4375

Once your container is started, you can copy files inside it to your host.

Use docker cp for this (https://docs.docker.com/engine/reference/commandline/cp/).

Example : docker cp CONTAINER:SRC_PATH DEST_PATH|-

Upvotes: 1

Related Questions