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

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.

主站蜘蛛池模板: 石林| 娄底市| 紫金县| 云林县| 荆门市| 河西区| 石城县| 新干县| 利川市| 清水河县| 巴楚县| 兰坪| 安仁县| 上饶县| 安宁市| 镶黄旗| 惠东县| 温宿县| 勃利县| 望江县| 龙山县| 隆回县| 郸城县| 本溪市| 宜丰县| 衢州市| 新建县| 安阳市| 厦门市| 宁国市| 武安市| 台南县| 荆门市| 肇源县| 台湾省| 沙坪坝区| 内乡县| 依安县| 陆丰市| 霍林郭勒市| 揭东县|