Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

525
Views
How to docker cp correctly?

I am trying to copy a file from my host to my container. I have already checked out many threads but neither of those work out for me.

File name, I'm trying to copy: ex.txt

Container folder where it needs to be: my_folder

user:~$ docker exec -it my_container bash
a5b13d9a55fd:~S ls
my_folder

What I have tried so far:

user:~$ docker cp ex.txt my_container:/my_folder/
no such directory

user:~$ docker cp ex.txt my_container:/my_folder/ex.txt
Error response from daemon: lstat /var/lib/docker/aufs/mnt/f7796d886aa3673be37b1d346190b7d6ba0ed64edf83bf62bff325f87eaec5eb/my_folder: no such file or directory

Please suggest where am I missing the code?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

EDIT: since the Image seems to use a none ROOT User you may try this:

docker cp ex.txt my_container:$HOME/my_folder/ex.txt

you should make sure that my_folder is already in the container, to be sure run this command at first:

docker exec my_container_name mkdir -p $HOME/my_folder
over 4 years ago · Santiago Trujillo Report

0

Please go through offical documentation properly.

Also check this out.

In your case this should work.

docker cp ex.txt my_container:/my_folder/

Update-1:

In your case, I doubt /my_folder is not present inside the container, this is what the error says.

Also quoting the line mentioned in official documentation.

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

So the /my_folder directory will not get created automatically.

Do this. docker exec -it my_container mkdir /my_folder and then run docker cp command.

Update-2:

If nothing is working then please try this, it worked for me.

$ cat /root/ex.txt
abc
$ docker run -itd alpine sh
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
921b31ab772b: Pull complete
Digest: sha256:ca1c944a4f8486a153024d9965aafbe24f5723c1d5c02f4964c045a16d19dc54
Status: Downloaded newer image for alpine:latest
35ad53b81c30f675b28a53e6a266f039cf49e90705d41e499deb4f17ab900255
$
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
35ad53b81c30        alpine              "sh"                3 seconds ago       Up 2 seconds                            mystifying_babbage
$
$ docker exec -it 35ad53b81c30 sh
/ # ls
bin    dev    etc    home   lib    media  mnt    opt    proc   root   run    sbin   srv    sys    tmp    usr    var
/ # mkdir /my_folder
$
$ docker cp /root/ex.txt mystifying_babbage:/my_folder/
$
$ docker exec -it 35ad53b81c30 sh
/ # ls /my_folder/
ex.txt
/ # cat /my_folder/ex.txt
abc
/ #

Hope this helps.

over 4 years ago · Santiago Trujillo Report

0

Ensure also not having typos in the container name, otherwise the same error will show up too

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!