Docker Community Forums

Share and learn in the Docker community.

"cp foo.txt mycontainer:/PATH/" does not work

Dear people,

these are my first steps in docker and i have the following problem: What is the best way to copy a file from a host to the Docker container?

Preface
I installed Docker from Gilbert Tanner to https://gilberttanner.com/blog/tensorflow-object-detection-with-tensorflow-2-creating-a-custom-model on my Linux desktop Ubuntu 18.04.
The used Docker version is 19.03.13, API 1.40 linux/amd64.

Problem
Now I want to copy one or more files from the host into the Docker container. In the tutorials the syntax is “docker cp foo.txt mycontainer:/”.
is executed, no error message is displayed, but no file is copied.

Also I have:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
54e99d73543f od “/bin/bash” 2 hours ago Up 2 hours compassionate_bartik

and i do
docker cp test.txt compassionate_bartik:/
I donẗ get a file in my container. But also no error message.

Only the following method works:
tar -cv *.txt | docker exec -i compassionate_bartik tar x -C .

What am I doing wrong with the method with cp?

Best regards
Joern

I have started working with Docker today.

Not primarily to learn Docker, but I have an application to install, elche is pre-installed under Docker. I find this practical and convenient.

So far everything works fine. But somehow I misunderstand the Docker documentation. I want to copy a file from the host to the Docker instance.

I have a Docker instance running:

Code
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
54e99d73543f od “/bin/bash” 2 hours ago Up 2 hours compassionate_bartik

This syntax “docker cp foo.txt mycontainer:/” does not work.

The command

Code
docker cp test.txt compassionate_bartik:/
is executed, no error message is displayed, but no file is copied.

Only this construction works:

Code
tar -cv *.txt | docker exec -i compassionate_bartik tar x -C .