Search code examples
dockernginxdocker-volumedocker-imageubuntu-20.04

Unable to mount volume between host and container in docker


Hope you are doing well during these troubled times.

I am new to docker and am trying to host some simple static content by customizing the index.html file which is saved in a folder named 'website' on my desktop.

My Configuration: Ubuntu-20.04 with WSL2 and docker Docker version 19.03.13, build 4484c46d9d on a Windows 10 Home Single Language edition with the OS Version 10.0.19042 and Build 19042.

I pulled nginx's latest image and but when I try attaching a local host volume to the html file inside nginx following the instructions on the nginx's docker page, it says

host@HOST:~$ docker run --name website -v /mnt/c/Users/HOST/Desktop/website:usr/share/nginx/html:ro -d -p 8080:80 nginx:latest
docker: Error response from daemon: invalid volume specification: '/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-20.04/<container id>:usr/share/nginx/html:ro': invalid mount config for type "bind": invalid mount path: 'usr/share/nginx/html' mount path must be absolute.
See 'docker run --help'.

I tried to troubleshoot the path but i cannot find where the images are stored on my computer. The only clue which i could find was in a github forum:

\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes

enter image description here

If I try to pass this path as the target container path, i still get an error.

Any help is appriciated.

-Manny


Solution

  • This was caused due to a missing / before the usr directory. This is what was being pointed out in the error:

    host@HOST:~$ docker run --name website -v /mnt/c/Users/HOST/Desktop/website:usr/share/nginx/html:ro -d -p 8080:80 nginx:latest
    docker: Error response from daemon: invalid volume specification: '/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-20.04/<container id>:usr/share/nginx/html:ro': invalid mount config for type "bind": invalid mount path: 'usr/share/nginx/html' mount path must be absolute.
    See 'docker run --help'.
    

    "invalid mount config for type "bind": invalid mount path: 'usr/share/nginx/html' mount path must be absolute."

    Instead, it should have been:

    docker run --name website -v /mnt/c/Users/HOST/Desktop/website:/usr/share/nginx/html:ro -d -p 8080:80 nginx:latest