Docker
Docker is core to Makester for both container image
management and integrating supporting containerised services. For example,
GitVersion. Wrap your wieldy, common Docker
commands into a make
target
and start being productive.
The Makester Docker subsystem help lists the available commands:
Example
A sample Dockerfile is provided by Makester to demonstrate basic capability.
Note
If you are running the following commands from Makester which has been setup within your
project repository, then replace resources/sample/Makefile
with makester/resources/sample/Makefile
.
To get help at any time:
Build a Docker image based off the "Hello World" image:
/usr/bin/docker build -t supa-cool-repo/my-project:99296c8 sample
Sending build context to Docker daemon 3.072kB
Step 1/1 : FROM hello-world
---> d1165f221234
Successfully built d1165f221234
Successfully tagged supa-cool-repo/my-project:99296c8
The resultant image build can be viewed:
REPOSITORY TAG IMAGE ID CREATED SIZE
supa-cool-repo/my-project 52c13b1 281099761321 10 months ago 9.14kB
To start a container from the supa-cool-repo/my-project
image:
Makester also supports image builds with BuildKit.
[+] Building 0.7s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 54B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/hello-world:latest 0.6s
=> CACHED [1/1] FROM docker.io/library/hello-world@sha256:aa0cc8055b82dc2509bed2e19b275c 0.0s
=> => resolve docker.io/library/hello-world@sha256:aa0cc8055b82dc2509bed2e19b275c8f46350 0.0s
=> exporting to oci image format 0.1s
=> => exporting layers 0.0s
=> => exporting manifest sha256:09fa5bdba956b1732511e681f392cabd75554ffbc85e9ea2c7ee4925 0.0s
=> => exporting config sha256:52cac4254827711f6b1c1c75c516538b7b95656723f8aa6a4f74a9a59b 0.0s
=> => sending tarball 0.1s
=> importing to docker 0.0s
Makester performs a couple of customisations for you behind the scenes to steamline the image build process with BuildKit. These include:
- Identifies your platform and uses that value to set the
--platform
todocker buildx build
. - Adds the
--load
switch todocker buildx build
so that the new image is exported into docker.
Warning
Without the --load
switch, the docker buildx build
process will display the following warning:
To see the new plan for docker buildx build
:
docker buildx build --platform linux/arm64 --load -t supa-cool-repo/my-project:<DOCKER_IMAGE_TAG> sample
Support for multi-architecture builds
Makester can now Leverage multi-CPU architecture support. However, there are some manual steps that need to be performed.
Define your target Docker platforms
To build an image that supports multiple architectures, you can define these by setting the
MAKESTER__DOCKER_PLATFORM
Makester variable. For example:
However, in the default docker image build system you may see this error:
To mitigate this error, we will need to create new buildx
builder. In this example, we will
call the new builder multiarch
. Change this name to suit your requirements::
Check to ensure that the new multiarch
builder has been selected for use (note multiarch *
):
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
multiarch * docker-container
multiarch0 unix:///var/run/docker.sock running v0.11.1 linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
Recall that Makester's docker buildx build
attempts to load the new image into docker's
registry. However, this is not possible with BuildKit as it runs as a completely different
process. Instead, we can load into a local registry server. Create the server as follows:
The image tag will also be updated to reflect the local registry server:
docker buildx build --platform linux/arm64,linux/amd64 --push -t localhost:15000/supa-cool-repo/my-project:52c13b1 sample
Warning
Makester will make subtle changes to your Docker build command based on whether the local registry server is running or not. If you experience unexpected behaviour, check the status of your server.
Now we can build the multi-platform container image:
Note
If you receive a :15000: connect: connection refused
error, you may need to add the following to
your Docker's daemon.json
configuration file:
To see the images in your local registry server, first list the catalog:
Next, get the list of available tags:
To access the new image from the local registry server:
The local registry server can now be terminated:
Create a tag to align with the project's naming convention:
Now it is possible to search for the new, multi-platform image as per normal:
REPOSITORY TAG IMAGE ID CREATED SIZE
supa-cool-repo/my-project 52c13b1 52cac4254827 10 months ago 9.14kB
Not convinced that the new images have been built with multi-platform support?:
docker buildx imagetools inspect localhost:15000/supa-cool-repo/my-project:52c13b
Name: localhost:15000/supa-cool-repo/my-project:52c13b1
MediaType: application/vnd.oci.image.index.v1+json
Digest: sha256:6a8497a3199b5a220c175ae8c3d0b11149f04b5191e94fcce49b16bdfd630e98
Manifests:
Name: localhost:15000/supa-cool-repo/my-project:52c13b1@sha256:73752638c848a53e033f1a7db6a1f2459e41cd291edbd4f6356593f915b2da63
MediaType: application/vnd.oci.image.manifest.v1+json
Platform: linux/arm64
Name: localhost:15000/supa-cool-repo/my-project:52c13b1@sha256:86954c5e397fdde46080e1bf13568bce1def33267125d6cbb9220eb0fd0a55f1
MediaType: application/vnd.oci.image.manifest.v1+json
Platform: linux/amd64
Image clean up
To delete the supa-cool-repo/my-project
image:
Command reference
Deploy a local registry server
As per notes on how to Deploy a registry server.
The registry can be accessed with curl
:
To stop the local image registry server:
Build your Docker image
Alternatively, leverage the features provided by BuildKit:
Create a buildx
builder
As per docker buildx create,
create a buildx
builder instance to leverage capabilities provided by BuildKit. Such as
multi-arch image builds:
Override MAKESTER__BUILDKIT_BUILDER_NAME
to set the name of the buildx builder instance:
Run your Docker images as a container
The container-run
target can be controlled in your Makefile
by overriding the
MAKESTER__RUN_COMMAND
parameter. For example:
MAKESTER__RUN_COMMAND := $(MAKESTER__DOCKER) run --rm -d --name $(MAKESTER__CONTAINER_NAME) $(MAKESTER__SERVICE_NAME):$(HASH)
Tag Docker image with the latest
tag
Tag Docker image with a custom versioning policy
Version defaults to 0.0.0-1
but this can be overridden by setting MAKESTER__VERSION
and
MAKESTER__RELEASE_NUMBER
in your Makefile
. Alternatively, to align with your preferred tagging
convention, override the MAKESTER__IMAGE_TAG
parameter. For example:
Remove your Docker image
Remove dangling Docker images
Variables
MAKESTER__IMAGE_TARGET_TAG
Unique identifier used to distinguish container image builds. Defaults to HASH.
MAKESTER__IMAGE_TAG_ALIAS
Convenience variable that is made up of the
MAKESTER__SERVICE_NAME and MAKESTER__IMAGE_TARGET_TAG
. For example:
MAKESTER__IMAGE_TAG_ALIAS=supa-cool-repo/my-project:52c13b1
MAKESTER__CONTAINER_NAME
Control the name of your image container (defaults to my-container
).
MAKESTER__IMAGE_TAG
Defaults to latest
.
MAKESTER__RUN_COMMAND
Override the image container run command that is initiated by make container-run
.
MAKESTER__BUILD_COMMAND
Override the command line options to docker build
or docker buildx build
to have more fine-grained control over the container image build process. For example, the following snippet overrides the image tag:
MAKESTER__DOCKER_PLATFORM
Override the --platform
switch to docker buildx
.
Multi-architecture builds are supported.
MAKESTER__LOCAL_REGISTRY
The host and IP of the local Docker image registry server which is used to configure
REGISTRY_HTTP_ADDR.
The default is 0.0.0.0:5000
. Although it is possible to override this variable, it only controls the
settings that the registry listens on within the container.
MAKESTER__LOCAL_REGISTRY_PORT
MAKESTER__LOCAL_REGISTRY_PORT
controls the local registry server host port that you can connect
to. The default is 15000
. You can override this setting if you detect a clash on port 15000
or
you want to run multiple local registry servers.
MAKESTER__BUILDKIT_BUILDER_NAME
The name to give to the
docker buildx create
builder. Defaults to multiarch
.