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

Sharing data between container and host with volumes

Container volumes are stored on the host, so you can access them directly from the machine running Docker - but they'll be in a nested directory somewhere in Docker's program data directory. The docker container inspect command tells you the physical location for a container's volumes, along with a lot more information - I've used it previously to fetch the container's IP address.

I can use explicit JSON formatting in the container inspect command, and extract just the volume information which is in the Mounts field. This command pipes the Docker output into a PowerShell cmdlet to show the JSON in a friendly format:

> docker container inspect --format '{{ json .Mounts }}' source | ConvertFrom-Json

Type : volume
Name : 3514e9620e667028b7e3ca8bc42f3615ea94108e2c08875d50c102c9da7cbc06
Source : C:\ProgramData\Docker\volumes\3514e96...\_data
Destination : c:\app\config
Driver : local
RW : True

Type : volume
Name : a342dc516e19fe2b84d7514067d48c17e5324bbda5f3e97962b1ad8fa4043247
Source : C:\ProgramData\Docker\volumes\a342dc5...\_data
Destination : c:\app\logs
Driver : local
RW : True

I've abbreviated the output, but in the source file you can see the full path where the volume data is stored on the host. I can access the container's files directly from the host, using the source directory. When I run this command on my Windows machine, I'll see the file created inside the container volume:

> ls C:\ProgramData\Docker\volumes\a342dc5...\_data

Directory: C:\ProgramData\Docker\volumes\a342dc5...\_data

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 22/06/2017 08:13 28 log-1.txt

Accessing the files on the host is possible this way, but it's awkward to use the nested directory location with the volume ID. Instead, you can mount a volume from a specific location on the host when you create a container.

主站蜘蛛池模板: 岐山县| 林口县| 嘉禾县| 朝阳县| 榆社县| 炉霍县| 遂川县| 垣曲县| 通城县| 郓城县| 龙胜| 合江县| 兰考县| 民丰县| 德化县| 神农架林区| 磐石市| 广州市| 韶山市| 东乡| 章丘市| 措美县| 弥勒县| 云南省| 萨迦县| 永胜县| 新和县| 馆陶县| 阳城县| 五常市| 偏关县| 安泽县| 张家川| 永修县| 东城区| 格尔木市| 古浪县| 通江县| 利川市| 宣城市| 右玉县|