Buildkit cross architecture building bug... or feature?

buildkit is now included with Docker Desktop and the Docker buildx plugin. We can now build an image for multiple CPU architectures by using the flag --platform in the docker buildx build command. For example docker buildx build --platform=linux/amd64,linux/arm64 .. You can however keep on using the native build platform by using the --platform=${BUILDPLATFORM} flag in your Dockerfile’s FROM instruction. For example: FROM--platform=${BUILDPLATFORM} golang:1.16-alpine3.13 AS builderYou will usually specify the TARGETPLATFORM argument further down in the Docker build stage block....

June 20, 2021 · 3 min · Quentin McGaw

Suggestion on how to improve cross CPU docker builds with the Dockerfile

Please read Buildkit cross architecture building bug instead, this page is actually wrong.

June 14, 2021 · 1 min · Quentin McGaw

The Go Dockerfile

There are various ways to organize your Dockerfile and CI. After having tried many solutions, I have a solid way to write your Dockerfile for your Go program. The Dockerfile is also heavily optimized for the Docker layer caching mechanism, to have fast rebuilds locally and on your CI. In this post, we will analyze such Dockerfile and analyze the structure of it, which is optimized for caching, secured and designed to contain everything....

June 5, 2021 · 11 min · Quentin McGaw

Go project structure

There is no right way to structure a Go project. But there is a best way to have a structured, clear and maintainable Go project structure. After seeing so many wrong-doings in the file structure of a Go project, making it unmaintainable, I thought it was time to write a post on that. We will examine what this structure is, why and what to avoid. The file structure In the following, we assume your application name is myapp and the project name is github....

June 5, 2021 · 5 min · Quentin McGaw

VSCode Go development container

In April 2019, VSCode released a new extension Remote Containers Development allowing you to code with your development environment in a Docker container. After having struggled somehow to install all the proper tooling for Go on my host, that looked like the perfect occasion to jump in. That is why I developed the Docker image qmcgaw/godevcontainer together with devtainr to have a blazing fast installation. The following diagram will explain the remote container development concept much better than I can ever explain it:...

June 5, 2021 · 3 min · Quentin McGaw

Docker without root

A lot of developers are not aware running a Docker container as root is risky security wise. A container is still isolated with the isolation of LXC, but running as root means it’s running as the same root as the on the host. An attacker gaining access to the container can thus do some damage since he has root access. There are multiple ways to avoid running as root but there are also many challenges that we address in the following....

June 4, 2021 · 4 min · Quentin McGaw

Cross CPU docker images using Go

Building cross CPU Docker images for Go programs is not a trivial task. With the excellent Go compiler and the recent improvements of Docker building, quite an advanced setup can be achieved to build Docker images for all CPU architectures supported by Docker and Go. What we’ll do We will design a Dockerfile cross building a simple Go program for Docker images supporting multiple CPU architectures. The aim is to have the statically compiled Go program in a final Docker image based on the alpine:3....

June 4, 2021 · 4 min · Quentin McGaw

Cross CPU docker images with Github Actions

We will design a continous integration (CI) using Github Actions to automatically build a simple Alpine based Docker image for every CPU architecture supported by Docker. The final image will only print the machine type for this experiment using uname -m. Make sure to check out the Conclusion which highlights more posts about Docker image cross compilation with programming languages such as Go. Prerequisites Have a Github account Have a Github repository Repository setup Have this minimal file structure in your repository:...

June 4, 2021 · 4 min · Quentin McGaw