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": "2024-12-15T18:09:47-08:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "C:\\ProgramData\\docker\\volumes\\volume01\\_data",
"Name": "volume01",
"Options": null,
"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:ltsc2025 powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\> ls C:\
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 12/15/2024 6:09 PM disk01
d-r--- 12/8/2024 2:48 PM Program Files
d-r--- 12/8/2024 2:26 PM Program Files (x86)
d-r--- 12/8/2024 2:48 PM Users
d----- 12/15/2024 6:11 PM Windows
-a---- 12/8/2024 2:26 PM 5647 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:ltsc2025 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 - [c25c556de0fc5e3b2caa739d56938da37a2edac8599e421e2b0790d420e28e8e, 9f979d883675f5821df9204420a233ceb685276cfb4c1bea6cb7b0320bad42bb]
# 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 c25c556de0fc5e3b2caa739d56938da37a2edac8599e421e2b0790d420e28e8e
PS C:\Users\Administrator> docker rm 9f979d883675f5821df9204420a233ceb685276cfb4c1bea6cb7b0320bad42bb
PS C:\Users\Administrator> docker volume rm volume01
volume01
|