租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

docker本地文件夹怎么映射,dockerfile sh

发布时间:2023-11-02 11:56:39

docker本地文件夹怎样映照

在Docker中,可以通过使用 -v 还是 --mount 参数来将本地文件夹映照到容器中。

  1. 使用 -v 参数进行文件夹映照:
docker run -v /host/path:/container/path <image>

这里,/host/path 是本地文件夹的路径,/container/path 是容器中相应的路径。这样,/container/path 中的内容将会与 /host/path 中的内容同步。

  1. 使用 --mount 参数进行文件夹映照:
docker run --mount type=bind,source=/host/path,target=/container/path <image>

一样,/host/path 是本地文件夹的路径,/container/path 是容器中相应的路径。这里的 --mount 参数提供了更多的选项,如指定读写权限(rorw),指定特定的文件系统类型等。

不管是使用 -v--mount,都可以将本地文件夹映照到容器中。这样,在容器中对 /container/path 的读写操作,都会直接反应到本地的 /host/path 中。