Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: Copying files from Docker container to host

I'm thinking of using Docker to build my dependencies on a Continuous Integration (CI) server, so that I don't have to install all the runtimes and libraries on the agents themselves.

To achieve this I would need to copy the build artifacts that are built inside the container back into the host. Is that possible?

like image 884
user2668128 Avatar asked Feb 26 '14 17:02

user2668128


People also ask

How do I copy a file from a Docker container to the host?

Obtain the name or id of the Docker container. Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container. The second parameter of the docker copy command is the location to save the file on the host.

How do I copy a directory from Docker to local container?

The docker cp utility copies the contents of SRC_PATH to the DEST_PATH . You can copy from the container's file system to the local machine or the reverse, from the local filesystem to the container. If - is specified for either the SRC_PATH or DEST_PATH , you can also stream a tar archive from STDIN or to STDOUT .


1 Answers

In order to copy a file from a container to the host, you can use the command

docker cp <containerId>:/file/path/within/container /host/path/target 

Here's an example:

$ sudo docker cp goofy_roentgen:/out_read.jpg . 

Here goofy_roentgen is the container name I got from the following command:

$ sudo docker ps  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                            NAMES 1b4ad9311e93        bamos/openface      "/bin/bash"         33 minutes ago      Up 33 minutes       0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp   goofy_roentgen 

You can also use (part of) the Container ID. The following command is equivalent to the first

$ sudo docker cp 1b4a:/out_read.jpg . 
like image 51
creack Avatar answered Sep 17 '22 23:09

creack