简体   繁体   中英

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

在此处输入图片说明

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

Any help is appriciated.

-Manny

On Windows, the paths must be named using Windows-style semantics . You should not use a leading slash in front of the path.

docker run -v c:\Users\[path]:c:\[containerPath]

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM