I can not copy in Docker Volume

cdrachellinux83@DESKTOP-RTS83TE:~$ docker volume inspect website
        "CreatedAt": "2022-02-17T17:47:00Z",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/website/_data",
        "Name": "website",
        "Options": {},
        "Scope": "local"
cdrachellinux83@DESKTOP-RTS83TE:~$ sudo cp -r ./someapp/* /var/lib/docker/volumes/website/_data
cp: target '/var/lib/docker/volumes/website/_data' is not a directory

If anyone knows what the problem is, it’ll help me a lot
thank you.

Hello @cdrachel,

the mountpoint you can see with docker volume inspect ... is some docker-internal mountpoint and could not be used for directly copying data to.
You can copy data to the volume if you mount it into a container and then user docker cp .... to copy data into the container’s mountpoint for this volume.
Sounds strange - it maybe is :slight_smile:

As an example I have created a docker-compose.yml running NginX and a volume containing the website’s data:

$ cat docker-compose.yml
version: '2.0'

    image: nginx:latest
      - '8090:80'
      - ./nginx-site.conf:/etc/nginx/conf.d/default.conf
      - mydata:/var/www/html


Within the output from docker container inspect 03_nginx_nginx_1 you can see something like this:

        "Mounts": [
                "Type": "volume",
                "Name": "03_nginx_mydata",
                "Source": "03_nginx_mydata",
                "Destination": "/var/www/html",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": ""

whereas a docker volume inspect 03_nginx_mydata returns

        "CreatedAt": "2022-02-20T12:24:11Z",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "03_nginx",
            "com.docker.compose.version": "1.29.2",
            "com.docker.compose.volume": "mydata"
        "Mountpoint": "/var/lib/docker/volumes/03_nginx_mydata/_data",
        "Name": "03_nginx_mydata",
        "Options": null,
        "Scope": "local"

Now you can copy files for the NginX’s-containers path /var/www/html (i.e. docker cp index.html 03_nginx_nginx_1:/var/www/html/) which will end up in the volume 03_nginx_mydata.

Maybe this helps a little?

1 Like

Hi, I just saw it earlier- and it helped me a lot!
Thank you very much!!!
I have another question - if possible - I could see that there is a container in Volume by the Docker Desktop, but I do not see if it copied what I wanted into it:

And when I run ls- I can not access the Volumes folder- so I can not see if it copied to the Volume website what I wanted:

Here I created a container with the volume (website)

cdrachellinux83@DESKTOP-RTS83TE:~$ docker run -d \
  --name devtest \
  --mount source=website,target=/app \
  nginx:latest>   --name devtest \
>   --mount source=website,target=/app \
>   nginx:latest
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
5eb5b503b376: Already exists
1ae07ab881bd: Pull complete
78091884b7be: Pull complete
091c283c6a66: Pull complete
55de5851019b: Pull complete
b559bad762be: Pull complete
Digest: sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767
Status: Downloaded newer image for nginx:latest

Here I ran docker container inspect

cdrachellinux83@DESKTOP-RTS83TE:~$ docker container inspect devtest
        "Mounts": [
                "Type": "volume",
                "Name": "website",
                "Source": "/var/lib/docker/volumes/website/_data",
                "Destination": "/app",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""

Here I copied by Destination

cdrachellinux83@DESKTOP-RTS83TE:~$ sudo cp ./someapp/*|- devtest:/app

Here I tried to see the data:

cdrachellinux83@DESKTOP-RTS83TE:~$ sudo ls -l /var/lib/docker/volumes/website/**_data**
ls: cannot access '/var/lib/docker/volumes/website/_data': No such file or directory
cdrachellinux83@DESKTOP-RTS83TE:~$ sudo ls -l /var/lib/docker/volumes/**website**
ls: cannot access '/var/lib/docker/volumes/website': No such file or directory
cdrachellinux83@DESKTOP-RTS83TE:~$ sudo ls -l /var/lib/docker/`volumes`
total 24
brw------- 1 root root 8, 16 Feb 15 04:10 backingFsBlockDev
-rw------- 1 root root 32768 Feb 15 04:10 metadata.db

What I see- that it fails to access the Volumes themselves (inside the Volumes folder) - maybe you know why?

Thank you so much for all the help !!

Hello @cdrachel,

I tried to reproduce the issue and was successful in doing all tasks. Maybe it helps and some of Docker’s basic concepts are a little bit clearer.

First I created a volume with docker volume create webtest
Then I ran the same command as you did to start the container docker run -d --name devtest --mount source=webtest,target=/app nginx:latest
Up to now it is nearly the same as you did.

But now there is a difference - I started a shell IN the running container with docker exec -it devtest bash

Now I checked the content of the /app/-directory with ls -la /app/ which resulted in an empty directory-listing. Now I exited the container’s shell with exit and are back on my standard-shell.

To copy the data of the current directory into the container’s /app/-path I used docker cp . devtest:/app/. In reality I copied it to the volume because the webtest-volume was mounted to the path /app/.

To verify that the data is now there I entered again the container’s shell with docker exec -it devtest bash and now the directory /app/ contains some data (to be verified with ls -la /app/).

After exiting the container’s shell again with exit I stopped the container (docker container stop devtest) and removed it (docker container rm devtest). But the volume webtest is still there :slight_smile:

If I created a NEW container with the same command as above (again mounting the volume to /app/) docker run -d --name devtest --mount source=webtest,target=/app nginx:latest the volume’s data is still/again available to the container - to be verified with a shell within the container docker exec -it devtest bash and list the directory’s content with ls -la /app/.

I don’t try to access the volume’s content directly from the host’s shell nor do I try to copy data to the volume using the Linux’s default cp-command.