#StackBounty: #windows #docker #containers #windows-server-2019 Docker build command creates large amount of folders in windowsfilter f…

Bounty: 50

I’m building a new image like so docker build . -t test and copy contents from host OS folder into it:


FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

RUN mkdir root
RUN cd root
RUN mkdir test
COPY test /root/test
    #USING 'COPY' here instead of 'ADD' because of https://stackoverflow.com/questions/24958140/what-is-the-difference-between-the-copy-and-add-commands-in-a-dockerfile

I get this output in Powershell:

PS D:Programs> docker build . -t test
Sending build context to Docker daemon  1.644GB
Step 1/7 : FROM mcr.microsoft.com/windows/servercore:ltsc2019
ltsc2019: Pulling from windows/servercore
4612f6d0b889: Pull complete
c67ded6868b6: Pull complete
Digest: sha256:1be9c8378b8c32d31538253a4b96169f5138a5f6d4c0a04e8d8f9a80b9ac8097
Status: Downloaded newer image for mcr.microsoft.com/windows/servercore:ltsc2019
 ---> d1724c2d9a84
Step 2/7 : SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
 ---> Running in 1bfefefbe433
Removing intermediate container 1bfefefbe433
 ---> 37de702deb33
Step 3/7 : RUN mkdir root
 ---> Running in e26d6b49ced7

    Directory: C:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         9/8/2021   1:07 PM                root

Removing intermediate container e26d6b49ced7
 ---> 451c4d3f3ea1
Step 4/7 : RUN cd root
 ---> Running in 74a228f8118f
Removing intermediate container 74a228f8118f
 ---> 3f175ac67f1d
Step 5/7 : WORKDIR /root
 ---> Running in 5f783d5b2332
Removing intermediate container 5f783d5b2332
 ---> 68b24e033f87
Step 6/7 : RUN mkdir test
 ---> Running in 5771bb7a593a

    Directory: C:root

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         9/8/2021   1:08 PM                test

Removing intermediate container 5771bb7a593a
 ---> 35fa0b2af157
Step 7/7 : COPY test /root/test
 ---> 60eab8242865
Successfully built 60eab8242865
Successfully tagged test:latest

It creates EIGHT(!) folders on the host OS in folder "dockerwindowsfilter"

This seems excessive, it looks like a folder for each step in my Dockerfile, so what are all these folders for and could I prevent creation/autodelete the unneeded ones to keep everything tidy?

Host OS: Windows Server 2019 standard Version 1809 17763.2114
Docker: version 20.10.4, build 110e091

Please note that I do NOT use the Docker Desktop application, see here how I installed Docker.

Update 1

I updated my Dockerfile based on @Noam’s suggestion like so:

#RUN mkdir root
#RUN cd root
#WORKDIR /root
WORKDIR /root #creates root directory if not exists, then enters it

After this change, 6 folders (instead of 8) are created in windowsfilter, so my hunch that Docker creates a folder for each command in Dockerfile seems to be correct.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.