Copy entire directory from container to host

Harry Blue picture Harry Blue · Oct 13, 2017 · Viewed 21.1k times · Source

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?

Answer

Sergiu picture Sergiu · Oct 13, 2017

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