docker 映射一个目录到宿主机
要将一个目录映射到宿主机,可以使用Docker的 -v 或 --volume 参数。以下是一些示例:
-
将宿主机上的
/path/to/host/dir目录映射到容器内的/path/to/container/dir目录:docker run -v /path/to/host/dir:/path/to/container/dir image_name -
将宿主机上的当前工作目录映射到容器内的
/app目录:docker run -v $(pwd):/app image_name -
将宿主机上的
/path/to/host/dir目录映射到容器内的/path/to/container/dir目录,并设置读写权限:docker run -v /path/to/host/dir:/path/to/container/dir:rw image_name
请注意,如果指定的宿主机目录不存在,Docker将自动创建它。
原文地址: http://www.cveoy.top/t/topic/iWtF 著作权归作者所有。请勿转载和采集!