Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
# create [volume01] volume
PS C:\Users\Administrator> docker volume create volume01
volume01
# display volume list
PS C:\Users\Administrator> docker volume ls
DRIVER VOLUME NAME
local volume01
# display details of [volume01]
PS C:\Users\Administrator> docker volume inspect volume01
[
{
"CreatedAt": "2022-01-20T19:42:23-08:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "C:\\ProgramData\\docker\\volumes\\volume01\\_data",
"Name": "volume01",
"Options": {},
"Scope": "local"
}
]
# run a container with mounting [volume01] to [C:\disk01] on container
PS C:\Users\Administrator> docker run -it -v volume01:C:\disk01 mcr.microsoft.com/windows/servercore:ltsc2022 powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\> ls C:\
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 1/20/2022 7:42 PM disk01
d-r--- 1/16/2022 5:18 AM Program Files
d----- 1/15/2022 9:05 PM Program Files (x86)
d-r--- 1/15/2022 9:23 PM Users
d----- 1/20/2022 7:45 PM Windows
-a---- 5/8/2021 3:26 AM 5510 License.txt
PS C:\> echo "Docker Volume test" | Out-File C:\disk01\testfile.txt -Encoding Default
PS C:\> exit
PS C:\Users\Administrator> Get-Content C:\ProgramData\docker\volumes\volume01\_data\testfile.txt
Docker Volume test
# possible to mount from other containers
PS C:\Users\Administrator> docker run -v volume01:C:\volume01 mcr.microsoft.com/windows/servercore:ltsc2022 powershell -c "Get-Content C:\volume01\testfile.txt"
Docker Volume test
# to remove volumes, do like follows
PS C:\Users\Administrator> docker volume rm volume01
Error response from daemon: remove volume01: volume is in use - [2641c52ffcf4859399840597f0b0aa3ff04155c950ff79c2cb5c9fa32c962ace, e0c015ca1a540ab48aeb835346966cf3578629f680d286a91f5262f844f24a12]
# if some containers are using the volume you'd like to remove like above,
# it needs to remove target containers before removing a volume
PS C:\Users\Administrator> docker rm 2641c52ffcf4859399840597f0b0aa3ff04155c950ff79c2cb5c9fa32c962ace
PS C:\Users\Administrator> docker rm e0c015ca1a540ab48aeb835346966cf3578629f680d286a91f5262f844f24a12
PS C:\Users\Administrator> docker volume rm volume01
volume01
|