要在Docker容器中挂载目录,可以使用-v
或--mount
选项来指定要挂载的目录。以下是两种方法:
-v
选项:docker run -v /host/path:/container/path image_name
这个命令将会在容器中挂载/host/path
目录到/container/path
目录。
--mount
选项:docker run --mount type=bind,source=/host/path,target=/container/path image_name
这个命令也会将/host/path
目录挂载到/container/path
目录。
无论使用哪种方法,都可以在启动容器时创建一个挂载点,使得容器可以访问主机的目录。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: 怎么查看docker镜像的日志