Reputation: 550
I am trying to build a Windows docker image which will copy my software to the image and unzip it. I am working on Windows 10 host. The steps are:
Prepare file Dockerfile. with the following lines:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
COPY image.zip c:\image.zip
CMD ["powershell.exe", "Expand-Archive -LiteralPath 'C:\image.zip' -DestinationPath 'c:\'"
Prepare a zip file called image.zip with some files.
Run command:
docker build -t test3 .
At this point the image is built. image.zip was copied to the image.
Run the container:
docker run --rm -it test3 powershell
From the container powershell run:
dir
At this point, I expect to see the content of "image.zip" which has been extracted during the build. But I don't, there is just "image.zip".
Upvotes: 7
Views: 53840
Reputation: 81
that's true ADD instruction extract the archived files but not all formates .. for example ADD
or COPY
instruction does not support extracting .zip
files but .tar
files and some more.
I suggest to do the following:
Dockerfile
ADD
instruction to copy the zip file from the source to the destinationRUN
instruction after ADD
instruction to extract the zip file.
like:ADD <file_name.zip> /<destination>
RUN unzip <file_name.zip>
Dockerfile
instructions.Upvotes: 7
Reputation: 550
Found a way to do it using .tar file insead of .zip and using "ADD" instead of "COPY":
The DOCKERFILE. now looks like this:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
ADD test3.tar c:/
The ADD command extracts the archive.
Upvotes: 9