I have a ubuntu docker container running on my docker desktop on macOS.
I want to install a docker inside that ubuntu docker container, do some configuration and migrate it to a ubuntu docker machine to run.
However, when I follow official instructions to use apt repository to install docker (apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin), the following error occurred:
Unpacking docker-compose-plugin (2.32.3-1~ubuntu.24.04~noble) ...
Setting up docker-buildx-plugin (0.19.3-1~ubuntu.24.04~noble) ...
Setting up containerd.io (1.7.25-1) ...
Setting up docker-compose-plugin (2.32.3-1~ubuntu.24.04~noble) ...
Setting up docker-ce-cli (5:27.5.0-1~ubuntu.24.04~noble) ...
Setting up docker-ce (5:27.5.0-1~ubuntu.24.04~noble) ...
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of restart.
The last two lines suggestion that something about run level was wrong.
Even if the apt command worked, you would need to manually execute the dockerd process or define it as a container command in the Dockerfile or compose or cli.
Instructions in the documentation is for normal Linux distibutions. A container is not a normal Linux distribution but a bunch of libraries and config files with a similar hierarchy but without systemd. Docker in Docker just means you run a Docker daemon inside a Docker container, but it doesnât mean you can install the daemon normally. There are existing dind images you could use: https://hub.docker.com/_/docker
The WSL-related issue you found was probably about WSL1 which was not a VM like WSL2. WSL2 was announced in 2019. So your issue is different, even though the error message is similar. One possible reason I can imagine is that you didnât run the container in privileged mode (especially if it was a temporary builder container) which would be necessary for the daemon too.
I tested the dind image you mentioned and it did work. Thank you very much.
I also used a ubuntu virtual machine on Parallels Desktop and installed docker on it to run a docker image, and it also worked.
Update:
I found that the reason I failed in my inital try to use docker in a ubuntu docker container was that I didnât launch the dockerd process.
I initially ran service docker start and the prompt said OK, which was misleading.
Just now I used ps -aux | grep 'docker' and found that nothing was launched by service docker start.
Instead, I just ran dockerd, and in another terminal ran docker run hello-world, and it did succeed.
It was most likely started but unless you run something in the foreground in the container, it wonât matter because the container still stops with the process in the background. You need a process in the foreground