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

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.

主站蜘蛛池模板: 青河县| 阳山县| 镇江市| 华阴市| 福安市| 贺州市| 大丰市| 阜宁县| 枞阳县| 宜良县| 望谟县| 弥勒县| 建阳市| 喀什市| 丰都县| 斗六市| 南投县| 博客| 岳普湖县| 慈利县| 澳门| 余江县| 独山县| 镇远县| 万州区| 普兰店市| 民县| 新竹市| 开远市| 太仆寺旗| 浦江县| 临邑县| 和静县| 高唐县| 玉门市| 新巴尔虎左旗| 普安县| 阜城县| 横山县| 收藏| 正定县|