2

I have a script that makes a directory inside a docker container and copies a file from the host to the new directory.

# $wpc is a variable holding the container name
#make the directory in the container
docker exec $wpc bash -c "mkdir -p /root/.ssh"
#stop container 
docker stop $wpc
#copy file to container
docker cp  ~/.ssh/id_rsa $wpc:/root/.ssh/id_rsa
# wait until the wordpress container is running 
docker start $wpc

but I get this error:

Error: No such container:path: <container_name>:\root\.ssh

Is the syntax wrong? I tried changing the permissions for the folder before the file is copied, with no luck.

I'm running docker on windows server 2019 and My Docker Info:

Client: Docker Engine - Enterprise
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        2ee0c57608
 Built:             11/13/2019 08:00:16
 OS/Arch:           windows/amd64
 Experimental:      true

Server: Docker Engine - Enterprise
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.24)
  Go version:       go1.12.12
  Git commit:       2ee0c57608
  Built:            11/13/2019 07:58:51
  OS/Arch:          windows/amd64
  Experimental:     true

Any help or info appreciated.

Austin Jones
  • 709
  • 1
  • 14
  • 29
  • Why are you stopping container after `mkdir` command? – anubhava Dec 02 '19 at 19:07
  • 1
    Because on windows 10 you cannot run filesystem operations against a running container. More info here: https://stackoverflow.com/questions/45654570/unable-to-copy-to-windows-container-docker-cp-on-windows-10 if I don't stop the container I get Error response from daemon: filesystem operations against a running Hyper-V container are not supported – Austin Jones Dec 02 '19 at 19:11
  • 1
    If you’re just trying to inject a file, the `docker run -v` option is probably a better choice. I’d design around needing to script `docker exec` and `docker cp` whenever that’s a possibility; if you `docker run` a container it should be completely autonomous. – David Maze Dec 02 '19 at 20:27
  • Is there not a way around this? Using cp in my case would be helpful. – Austin Jones Dec 03 '19 at 13:14

1 Answers1

-1

OK, this isn't exactly answering the question, but this is the only question where I saw the \ characters in the error message, and I've been battling this issue all morning.

I found one workaround for this problem. Instead of using a loop like this:

foreach ($file in Get-ChildItem libfoo*) {
  docker cp $file mycontainer:/usr/local/lib
}

I put all of the files I wanted to copy into a directory, and copied the directory:

mkdir libs
mv libfoo* libs
docker cp .\libs mycontainer:/usr/local/lib

It seems to work unless the target directory is /.

  • This answer doesn't provide any value to the question. What you've done in the answer is exactly the same as what the OP as said they've done and this doesn't show that it solves the issue. – Newteq Developer Apr 22 '21 at 14:49