Search code examples
windows-containerdocker-in-docker

How to install Docker Desktop inside a Windows Server Core based container


Haven't come across any article that says how to setup Docker in Docker for Windows (native, not WSL). Trying to build a Windows Server Core based image but from within a Windows Server Core Container. Is this possible?


Solution

  • So, I took some time to test this out and it turns out that it actually works: Windows container running inside a Windows container

    The catch here is that the docker engine on the container needs to be mapped to the docker engine from the underlying container. Here is the docker file I used:

        # escape=`
    FROM mcr.microsoft.com/windows/servercore:ltsc2022
    
    RUN powershell -Command `
            $ErrorActionPreference = 'Stop'; `
            $ProgressPreference = 'SilentlyContinue'; `
            Invoke-WebRequest `
                -Uri https://download.docker.com/win/static/stable/x86_64/docker-20.10.15.zip `
                -OutFile docker.zip; `
            Expand-Archive docker.zip -DestinationPath 'C:\Program Files'; `
            Remove-Item docker.zip -Force `
        && setx /M PATH "%PATH%;C:\Program Files\docker"
    

    Here are the commands I ran:

    docker run -i -v \\.\pipe\docker_engine:\\.\pipe\docker_engine inception:v1 powershell
    

    This will open a container interactively. From there, run:

    docker run --rm mcr.microsoft.com/windows/servercore:ltsc2022 cmd /c hostname