The command
This is a short snippet I use to build and push Linux Docker images on my M1 Macbook Air.
docker buildx build --platform linux/amd64 \
-t <namespace>/<repository>:<tag> \
-t <namespace>/<repository>:latest . \
--push
I’m tagging the image twice, once with a unique tag and once with latest
. This is so that I can use the latest
tag in my CI/CD pipeline but don’t lose the image history in my registry in case I need to roll back.
For example to build and push an image to Docker Hub if my username was mrdocker
and my repo name is awesome_app
and the tag the commit hash:
docker buildx build --platform linux/amd64 \
-t mrdocker/awesome_app:123abc45de \
-t mrdocker/awesome_app:latest . \
--push
Note that if don’t want to push and just need the image locally you can replace the --push
with --load
.
Happy building!