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

1.5k Views Asked by At

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?

3

There are 3 best solutions below

0
On BEST ANSWER

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
1
On

Docker Desktop should be used on Windows 10/11 only. For Server environments, which Windows containers are based on, you should install the Docker/Mirantis engine. However, I'm not entirely sure this would work and even if it does (one can try), it should not be supported.

0
On

FYI, from @vinicius response you might need to specify --network flag when building the image i.e docker build --network="Default Switch" -t inception:v1 .