Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker cp throws "No such container:path" on running instance [closed]

Tags:

docker

After trying docker cp from here, it still throws a Error: No such container:path:...

enter image description here

What am I doing wrong?

  • The container is running
  • I can run docker exec commands
  • docker cp fails
like image 732
ndemasie Avatar asked Oct 30 '20 17:10

ndemasie


People also ask

Does docker CP create directory?

docker cp does not create parent directories for DEST_PATH if they do not exist.

How do I copy multiple files from docker container to local machine?

Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH Copy files/folders between a container and the local filesystem Use '-' as the source to read a tar archive from stdin and extract it to a directory destination in a container.

How do I keep docker running?

Dockerfile Command to Keep the Container Running Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. Method 2: You can run the container directly passing the tail command via arguments as shown below. Method 3: Another method is to execute a sleep command to infinity.


Video Answer


1 Answers

From the documentation:

The docker cp command assumes container paths are relative to the container’s / (root) directory.

Source: https://docs.docker.com/engine/reference/commandline/cp/#extended-description

This means that, when your docker exec [CONTAINER] ls is affected by the WORKDIR, your docker cp is not.

What you should do from there is to run:

  1. docker exec [CONTAINER] pwd
  2. Use what this yields you in the docker cp command to have a fully qualified path to use in you docker cp command

e.g. from the httpd image:

$ docker run -d --name httpd httpd

$ docker exec httpd pwd
/usr/local/apache2

$ docker exec httpd ls
bin
build
cgi-bin
conf
error
htdocs
icons
include
logs
modules

$ docker cp httpd:/usr/local/apache2/conf .

All this because the httpd image defines a WORKDIR on the folder /usr/local/apache2.

like image 105
β.εηοιτ.βε Avatar answered Oct 19 '22 02:10

β.εηοιτ.βε