0

I am trying to follow this question as a guide for how to copy a file from a docker container back to the host however I am getting a permission denied error as can be seen in the following copy of my terminal:

mdbl@mdblLXPS:~/Documents/research/docker/copying$ ls -ltr
total 12
-rw-rw-r-- 1 mdbl mdbl  28 Jan  2 23:26 Dockerfile
-rw-rw-r-- 1 mdbl mdbl 368 Jan  2 23:52 script.sh
-rwxrwxrwx 1 mdbl mdbl  15 Jan  3 00:16 test.txt
mdbl@mdblLXPS:~/Documents/research/docker/copying$ cat Dockerfile 
FROM alpine
COPY test.txt .
mdbl@mdblLXPS:~/Documents/research/docker/copying$ cat test.txt 
this is a test
mdbl@mdblLXPS:~/Documents/research/docker/copying$ cat script.sh 
echo create the image
sudo docker build -t testimg .
echo
echo list the newly created image
sudo docker images | head -2
echo
echo create the container
sudo docker container create --name mycont testimg
echo
echo list the newly created container
sudo docker container ls -a | head -2
echo
echo try copying test.txt from the container
sudo docker cp mycont:/test.txt .
mdbl@mdblLXPS:~/Documents/research/docker/copying$ source script.sh 
create the image
Sending build context to Docker daemon  4.096kB
Step 1/2 : FROM alpine
 ---> 49176f190c7e
Step 2/2 : COPY test.txt .
 ---> 70b40a27f26d
Successfully built 70b40a27f26d
Successfully tagged testimg:latest

list the newly created image
REPOSITORY               TAG       IMAGE ID       CREATED                  SIZE
testimg                  latest    70b40a27f26d   Less than a second ago   7.05MB

create the container
9c9396df4ab3e0538eb1aa995f13852d5328fbaa5597c82b731bb177cf809068

list the newly created container
CONTAINER ID   IMAGE          COMMAND                  CREATED                  STATUS                           PORTS     NAMES
9c9396df4ab3   testimg        "/bin/sh"                Less than a second ago   Created                                    mycont

try copying test.txt from the container
unlinkat /home/mdbl/Documents/research/docker/copying/test.txt: permission denied

I create a docker image from an alpine base image that contains a test file test.txt. Then I create a container from this image and try to copy this file back to the host, however I get the error unlinkat /home/mdbl/Documents/research/docker/copying/test.txt: permission denied. This is despite the fact that test.txt has full permissions associated to it as can be seen by the ls -ltr command. Why is this and how can I resolve this error?

Mathew
  • 1,116
  • 5
  • 27
  • 59
  • 1
    What are the permissions on `/home/mdbl/Documents/research/docker/copying/test.txt` on the host? – Hans Kilian Jan 03 '23 at 08:09
  • @HansKilian I just re-ran the script with a slight modification so as to answer your question. Thanks for the suggestion. You can now see `test.txt` has full permissions. – Mathew Jan 03 '23 at 08:19
  • It should be better to post this question in [superuser.com](https://superuser.com). Here in stackoverflow you risk being banned. – bert Jan 03 '23 at 08:21
  • I can't reproduce your issue. When I run your script, it works as it should. Also, you won't get banned, but your question might get closed if enough people think that it's off topic. So far, noone has voted to close it. – Hans Kilian Jan 03 '23 at 08:29
  • @bert , I may re post this on superuser then. Thanks for the suggestion. – Mathew Jan 03 '23 at 22:59
  • @HansKilian, Thanks for looking into this for me. I'm not sure where to go from here, so I've decided to print out my files to console and then capture standard out rather than copy the file over. This is a rather hacky solution, but its the best I can come up with for the moment. Thanks for your time. – Mathew Jan 03 '23 at 23:00

0 Answers0