Search code examples
dockerdockerfilealpine-linux

How do install and start daemon Docker in an Alpine container?


I work from Docker on Windows 11. I use Dockerfile to create an image:

FROM alpine:latest

RUN apk add docker
RUN apk add openrc

When viewing the Docker version in the Alpine image, I get:

Docker version 23.0.6, build ef23cbc4315ae76c744e02d687c09548ede461bd

When I want to look at the docker status, I enter:

status service docker

But I get an error:

 * You are attempting to run an openrc service on a
 * system which openrc did not boot.
 * You may be inside a chroot or you may have used
 * another initialization system to boot this system.
 * In this situation, you will get unpredictable results!
 * If you really want to do this, issue the following command:
 * touch /run/openrc/softlevel

Next I enter what is prepositional (touch /run/openrc/softlevel) and get another error:

touch: /run/openrc/softlevel: No such file or directory

After that I want to check the list of images:

docker images

return:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

And final commands:

service docker start

return:

* WARNING: docker is already starting

And:

service docker stop

return:

* ERROR: docker stopped by something else

I don't understand what's the matter at all, since I'm a beginner to using Linux.


Solution

  • To clarify the discussion in the comments, and the solution you found, it sounds like you have a Windows host onto which Docker Desktop is installed. You have an Alpine container in which the Docker client command is installed. You issued a basic command (docker images) inside the running container and found that it did not work. This is because, by the default, the console command will expect Docker is running locally (in this case in the container).

    Your solution was thus:

    docker run \
        -v /var/run/docker.sock:/var/run/docker.sock \
        ...
    

    This has the effect of sharing the Unix socket from the host (where Docker is running) to the container (where you only have a client, not a server).

    This technique is helpful if you want to run some code in isolation from the host, but you still need access to your existing Docker images.