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

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.

主站蜘蛛池模板: 辉县市| 鹰潭市| 麻江县| 洛南县| 炎陵县| 呼和浩特市| 五寨县| 浦江县| 民乐县| 福州市| 剑河县| 车险| 盘锦市| 英山县| 遵义市| 康定县| 乐亭县| 三河市| 赞皇县| 阳原县| 灵石县| 鹿泉市| 罗甸县| 西昌市| 兴文县| 钦州市| 房产| 乐昌市| 巴东县| 顺昌县| 宁城县| 四川省| 小金县| 宁德市| 米林县| 桂平市| 锦州市| 谢通门县| 九寨沟县| 如东县| 泽普县|