HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerMinor

Does building a Docker image require the Docker daemon to be running?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
imagethedockerbuildingrunningdoesrequiredaemon

Problem

I am trying to get my feet wet with Docker/containers. I started with this tutorial:

Getting Started · Spring Boot with Docker

It works fine, but I was surprised it is necessary to have the "dockerd" daemon running to build an image. It connects to it using localhost and a port number as part of executing the Maven build. Why is this required (and can it be avoided)? I mean, in many cases the image will have to be run on a separate platform anyway. It is particularly annoying, because I am building on Windows where Docker requires you to have Hyper-V enabled, which causes other issues (for instance that you can't use VMware on the same machine).

Due to the problems, I resorted to building it all inside a Linux VM (which then ran the Docker daemon).

Another thing which might be related to the above: It seems the build process doesn't leave the image on disk; it is installed directly into the repository managed by the Docker daemon. I can then export the image from the command line, and I suppose (haven't tried) this image could be moved to another machine and run from there. But how do I build "just" the image without having it deployed anywhere, etc.? It just needs to produce the artifacts in the local file system and leave it at that. Maybe that would also remove the requirement for having Docker running?

The command the tutorial uses for running Maven is:

./mvnw install dockerfile:build


However, trying alternatives to "install" (such as "package", etc.) seemingly doesn't change the behavior.

Solution

Each command in the Dockerfile is processed as a separate step. Every step from the build process gets executed in a dedicated container. It starts from Step 1 (the first command in the Dockerfile). That step is run in a container and if it is successful, a commit to a temporary image (let's call it image A) takes place. Then, Step 2 is executed in a container which is run from image A ... and so on until the final step is executed successfully. And as Tensibai commented - how do you think to run a container without the daemon?

So, yes - building a docker image requires the docker daemon to be running.

Context

StackExchange DevOps Q#4326, answer score: 7

Revisions (0)

No revisions yet.