官术网_书友最值得收藏!

Mounting a local container host directory using bind mounts

Bind mounts are the simplest form of persistent storage that is shared between the container and the host machine. In this way, you can mount any existing directory from the host filesystem in the container. It is also possible to "overwrite" an existing directory in the container with host directory contents, which may be useful in some scenarios. In general, volumes are the recommended storage solution, but there are a few cases where bind mounts can be useful:

  • Sharing configuration between the host and the container. A common use case may be DNS configuration or the hosts file.
  • In development scenarios, sharing build artifacts that were created on the host so that they can be consumed inside the container.
  • On Windows, mounting SMB file shares as directories in the container.
Volumes can be seen as an evolution of bind mounts. They are fully managed by Docker, without tight coupling to the container host filesystem being visible to the user.

Creating a bind mount for a container requires the docker run command to be specified with an additional parameter, type=bind, for the --mount flag. In this example, we will mount the host's C:\Users directory as C:\HostUsers in the container:

docker run -it --rm `
--isolation=process `
--mount type=bind,source=C:\Users,target=C:\HostUsers `
mcr.microsoft.com/powershell:windowsservercore-1903

You can verify that any changes performed to C:\HostUsers will also be visible on the host machine in C:\Users.

Windows-specific features and the limitations of bind mounts can be found in the official documentation from Microsoft: https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-storage#bind-mounts.

In the next section, we are going to learn how to leverage bind mounts in order to use remote or cloud storage in Windows containers.

主站蜘蛛池模板: 四川省| 邯郸县| 威宁| 广河县| 新闻| 静乐县| 辽阳县| 苏尼特右旗| 常宁市| 嘉禾县| 宿州市| 绥滨县| 射阳县| 镇沅| 云安县| 西乌珠穆沁旗| 明溪县| 土默特右旗| 洪洞县| 名山县| 宁海县| 博乐市| 漳浦县| 资中县| 桦川县| 克东县| 南溪县| 吴堡县| 溧水县| 壤塘县| 纳雍县| 兴海县| 太仓市| 万源市| 江津市| 甘孜县| 台中县| 通渭县| 杭锦旗| 福清市| 高台县|