[英]How to mount a single file with `docker run`?
In docker-compose, this works fine:在 docker-compose 中,这工作正常:
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
相同的操作:
$ 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:我也尝试使用--mount
,结果相同:
$ 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 run -v
选项的左侧必须是卷名或绝对路径。 Docker Compose understands relative paths in volumes:
, but plain Docker doesn't. Docker Compose 理解volumes:
,但普通的 Docker 不理解。
You need to include the current directory name in the option.您需要在选项中包含当前目录名称。 Using the $PWD
environment variable for this is common:为此使用$PWD
环境变量很常见:
docker run ... \
-v "$PWD/web_server/local-nginx.conf:/etc/nginx/nginx.conf" \
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.