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?
