moby: Windows: cannot put data in volumes with `docker build`
What works on Linux
cat .\Dockerfile.linux
FROM ubuntu
RUN mkdir /test && touch /test/file.txt
VOLUME /test
docker build -t vol-test -f .\Dockerfile.linux .
docker run vol-test
docker volume ls
...
docker volume ls
DRIVER VOLUME NAME
local 7715b61dd901682ed48825ae2db8a24d31bdf3ea0bd0a5098a4c8de2e624634f
docker run -ti -v 7715b61dd901682ed48825ae2db8a24d31bdf3ea0bd0a5098a4c8de2e624634f:/foo ubuntu ls /foo
file.txt
What works on Windows
docker run -v test-vol:C:\test microsoft/nanoserver powershell -c New-Item C:\test\foo.txt
Directory: C:\test
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/22/2017 10:54 PM 0 foo.txt
docker run -v test-vol:C:\foo microsoft/nanoserver powershell -c ls c:\foo
Directory: C:\foo
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/22/2017 10:54 PM 0 foo.txt
What doesn’t work on Windows
cat .\Dockerfile.win
FROM microsoft/nanoserver
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN mkdir C:\test ; New-Item -Type File C:\test\foo.txt
VOLUME C:\\test
docker build -t win-vol -f .\Dockerfile.win .
...
docker run win-vol
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: container 756d36348d89bd4bae0ee91e44a91f6ee2ce794d588efd5705db68ec5fef241e encountered an error during Start: failure in a Windows system call: The connection with the Virtual Machine hosting the container was closed. (0xc037010a).
Describe the results you received:
Error
Describe the results you expected:
That docker run
of image with VOLUME
declaration works, and will product volume with data in it.
Output of docker version
:
Docker 1.13.0 for both Linux and Windows
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 3
- Comments: 18 (6 by maintainers)
@alparamonov that approach is right, this example works as expected:
Build, and when you run you see the file in the volume:
@thaJeztah thanks for clarifying! I can actually live with the fact that the destination directory of a mount must be empty.
But is there also an explanation what happens when @alparamonov moved the VOLUME command to the top of the Dockerfile? Because I can reproduce his findings.
@sixeyed That seems weird because a similar Dockerfile produces the expected result under Linux. I would expect both platforms to behave identically.