Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy entire directory from container to host

I'm trying to copy an entire directory from my docker image to my local machine.

The image is a keycloak image, and I'd like to copy the themes folder so I can work on a custom theme.

I am running the following command -

docker cp 143v73628670f:keycloak/themes ~/Development/Code/Git/keycloak-recognition-login-branding

However I am getting the following response -

Error response from daemon: Could not find the file keycloak/themes in container 143v73628670f

When I connect to my container using -

 docker exec -t -i 143v73628670f /bin/bash

I can navigate to the themes by using -

cd keycloak/themes/

I can see it is located there and the files are as expected in the terminal.

I'm running the instance locally on a Mac.

How do I copy that entire themes folder to my local machine? What am I doing wrong please?

like image 370
Harry Blue Avatar asked Oct 13 '17 11:10

Harry Blue


People also ask

How do I copy a directory from a Docker 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 .

How do I copy file from container to 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.


1 Answers

EDIT

As a result of running 'pwd' your should run the Docker cp command as follows:

docker cp 143v73628670f:/opt/jboss/keycloak/themes ~/Development/Code/Git/keycloak-recognition-login-branding

You are forgetting the trailing ' / '. Therefore your command should look like this:

docker cp 143v73628670f:/keycloak/themes/ ~/Development/Code/Git/keycloak-recognition-login-branding

Also, you could make use of Docker volumes, which allows you to pass a local directory into the container when you run the container

like image 105
Sergiu Avatar answered Oct 12 '22 21:10

Sergiu