trial999
trial999

Reputation: 1716

From inside the docker container i want to copy the file in to the host machine

I have a docker container that basically runs a jar and creates an output json file. Is there any way i can copy this file into a folder in the docker host before the docker run exits ? .I have tried the below approach and it works fine.

docker run image1
docker cp <container id>:<path in container> <host file path>

Above command copies the file from the container to the docker host. However for this to work i have to ensure that the container doesn't exit in the mean time (by using a sleep in the program thats run in the jar). So a better approach will be to actually copy the file into the host from within the container.

Upvotes: 1

Views: 3940

Answers (1)

Cortwave
Cortwave

Reputation: 4907

The best decision is to have shared volume for container:

docker run -v /volume/on/your/host/machine:/volume/on/container image1 

You can read more here https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/

Upvotes: 5

Related Questions