- Docker on Windows
- Elton Stoneman
- 278字
- 2021-07-02 12:47:57
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.
- 全屋互聯:智能家居系統開發指南
- 電腦組裝與系統安裝
- 曝光:Linux企業運維實戰
- Extending Puppet
- Moodle 3.x Teaching Techniques(Third Edition)
- Mobile First Design with HTML5 and CSS3
- STM32庫開發實戰指南:基于STM32F4
- Windows 7中文版從入門到精通(修訂版)
- VMware NSX Cookbook
- 一學就會:Windows Vista應用完全自學手冊
- 計算機系統:基于x86+Linux平臺
- 云原生落地:產品、架構與商業模式
- INSTANT Galleria Howto
- Building Telephony Systems With Asterisk
- Windows 7使用詳解(修訂版)