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

Sharing data between the 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, including the container's ID, name, and the virtual IP address of the container in the Docker network.

I can use JSON formatting in the container inspect command, passing a query to extract just the volume information 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 : 65ab1b420a27bfd79d31d0d325622d0868e6b3f353c74ce3133888fafce972d9
Source : C:\ProgramData\docker\volumes\65ab1b42...\_data
Destination : c:\app\config
Driver : local
RW : TruePropagation :

Type : volume
Name : b1451fde3e222adbe7f0f058a461459e243ac15af8770a2f7a4aefa7516e0761
Source : C:\ProgramData\docker\volumes\b1451fde...\_data
Destination : c:\app\logs
Driver : local
RW : True

I've abbreviated the output, but in the Source field 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 that 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\b1451fde...\_data
Directory: C:\ProgramData\docker\volumes\b1451fde3e222adbe7f0f058a461459e243ac15af8770a2f7a4aefa7516e0761\_data

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 06/02/2019 13:33 19 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.

主站蜘蛛池模板: 泰宁县| 博爱县| 定襄县| 玛曲县| 彝良县| 连平县| 五指山市| 兴宁市| 繁昌县| 开鲁县| 凭祥市| 漳州市| 泽库县| 隆回县| 铅山县| 互助| 北流市| 乌拉特前旗| 长丰县| 延安市| 绍兴县| 新丰县| 朝阳区| 广昌县| 白玉县| 红河县| 定西市| 张家川| 青阳县| 文昌市| 濮阳县| 吉水县| 天门市| 邯郸市| 汪清县| 宝丰县| 翁源县| 东台市| 三河市| 黔东| 大余县|