1. Download the Dockerfile and the docker-compose.yaml files to a folder. Change directory to this folder.
$ docker build -t <username/repository> .
$ docker image ls
$ docker run -itdP --name ubuntu_example <username/repository>
$ docker port ubuntu_example 22
0.0.0.0:32770 <-- this port is random
$ ssh ubuntu@localhost -p <listed_port>
7. For multi-architecture builds, we will leverage the buildx experimental feature of Docker. To enable buildx, enable the Command Line Experimental Features of Docker. To accomplish this, run the following command from the terminal that will be used to build the container. If you are running Mac OS-X and have Docker Desktop installed, you can enable the experimental features from preferences menu.
$ export DOCKER_CLI_EXPERIMENTAL=enabled
8. To support building different architectures, register multi-architecture QEMU kernel handlers with host kernel by execute the following command to run the binfmt docker container. You man need to run this command each time you reboot your host machine.
$ docker run -it --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64
$ docker buildx create --name mybuilder
$ docker buildx use mybuilder
10. To ensure the builder is setup correctly, execute the following command and verify the output is similar to what is shown below. It is important to verify the desired target architecture is listed in Platforms.
$ docker buildx inspect --bootstrap
Name: mybuilder
Driver: docker-container
Nodes:
Name: mybuilder0
Endpoint: unix:///var/run/docker.sock
Status: running
Platforms: linux/amd64, linux/arm64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
$ docker login
12. Once the builder is setup, we can build the Docker image(s) and push to the repository that was created previously. In this example, the Docker image is built for the ARM7 architecture. Also note that you need to specify your repository information.
$ docker buildx build --platform linux/arm/v7 --no-cache -t <username/repository>:<tag> . --push