- Docker on Windows
- Elton Stoneman
- 269字
- 2021-07-02 19:53:21
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.
- 多媒體CAI課件設(shè)計與制作導(dǎo)論(第二版)
- C#高級編程(第10版) C# 6 & .NET Core 1.0 (.NET開發(fā)經(jīng)典名著)
- 數(shù)據(jù)庫程序員面試筆試真題與解析
- 編程的修煉
- Blockly創(chuàng)意趣味編程
- Visual Basic程序設(shè)計與應(yīng)用實踐教程
- Bootstrap 4:Responsive Web Design
- Hands-On Natural Language Processing with Python
- Mastering Machine Learning with R
- 例說FPGA:可直接用于工程項目的第一手經(jīng)驗
- Getting Started with RethinkDB
- Serverless工程實踐:從入門到進階
- Python編程零基礎(chǔ)入門
- 零基礎(chǔ)學(xué)C++
- Java EE 8 Development with Eclipse