Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

524
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

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

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda