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

  • Docker on Windows
  • Elton Stoneman
  • 296字
  • 2021-07-02 19:53:21

Mounting volumes from host directories

You use the --volume option to explicitly map a directory in a container from a known location on the host. The target location in the container can be a directory created with the VOLUME command, or any directory in the container's filesystem. The source is the location on the host filesystem.

I'll create a dummy configuration file for my app in a directory on the C drive on my Windows machine:

PS> mkdir C:\app-config | Out-Null
PS> echo 'VERSION=17.06' > C:\app-config\version.txt

Now I'll run a container which maps a volume from the host, and read the configuration file which is actually stored on the host:

> docker container run `
--volume C:\app-config:C:\app\config `
dockeronwindows/ch02-volumes `
cat C:\app\config\version.txt
VERSION=17.06

The --volume option specifies the mount in the format {source}:{target}. The source is the host location, which needs to exist. The target is the container location, which does not need to exist - but needs to be empty if it does exist.

Volume mounts are different in Windows and Linux containers. In Linux the target folder does not need to be empty, and Docker will merge the contents from the source into the target. Docker on Linux also lets you mount a single file location, but on Windows you can only mount whole directories.

Volume mounts are useful for running stateful applications in containers, like databases. You can run SQL Server in a container, and have the database files stored in a location on the host - which could be a RAID array on the server. When you have schema updates, you remove the old container and start a new container from the updated Docker image. You use the same volume mount for the new container, so the data is preserved from the old container.

主站蜘蛛池模板: 四会市| 临桂县| 泸西县| 盘锦市| 宝坻区| 理塘县| 石柱| 乐山市| 灯塔市| 桐城市| 兰考县| 辰溪县| 萨迦县| 广灵县| 连城县| 华宁县| 梓潼县| 安新县| 武乡县| 四子王旗| 龙江县| 新巴尔虎左旗| 长岛县| 鄱阳县| 松原市| 海原县| 甘泉县| 弥勒县| 萍乡市| 郴州市| 呼玛县| 且末县| 鹤山市| 抚远县| 保山市| 舞钢市| 伊宁市| 驻马店市| 栖霞市| 上饶县| 呼伦贝尔市|