In docker-compose, this works fine:
nginx:
image: nginx:latest
network_mode: host
volumes:
- web_server/local-nginx.conf:/etc/nginx/nginx.conf
ports:
- 8080:8080
However, if I try to do the same thing using docker run
directly:
$ docker run --network host -p 8080:8080 \
-v "web_server/local-nginx.conf:/etc/nginx/nginx.conf" \
nginx:latest
I get errors:
docker: Error response from daemon: create web_server/local-nginx.conf: "web_server/local-nginx.conf"
includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed.
If you intended to pass a host directory, use absolute path.
I also tried using --mount
, with the same results:
$ docker run -p 8080:8080 --network host \
--mount src="web_server/local-nginx.conf",dst="/etc/nginx/nginx.conf" \
nginx:latest
The left-hand side of the docker run -v
option must be a volume name or an absolute path. Docker Compose understands relative paths in volumes:
, but plain Docker doesn't.
You need to include the current directory name in the option. Using the $PWD
environment variable for this is common:
docker run ... \
-v "$PWD/web_server/local-nginx.conf:/etc/nginx/nginx.conf" \
...
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.