Log inSign up

Build your own images and publish them to a registry

Describe the image in a Dockerfile, build it with docker build -t app:1.0 ., add a registry name with docker tag, sign in with docker login and upload with docker push. For images that must run on both x86 and ARM machines, docker buildx build --platform linux/amd64,linux/arm64 --push does the build and the upload in one step.

Topic: Containers and PaaS · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

What do you need to build images on a server?

A Docker Engine from the official repository already includes BuildKit and the buildx plugin, so no extra tools are needed. If the engine is missing, install it with the Docker Engine tutorial. Confirm the pieces are in place:

docker version --format '{{.Server.Version}}'
docker buildx version
docker buildx ls

Builds use CPU, memory and disk heavily while they run. A build server or CI runner benefits from more vCPU and fast NVMe storage, and from a scheduled cleanup of the build cache.

How do you write a good Dockerfile?

Start from a small, maintained base image, copy dependency lists before the source code so the cache works for you, and run the process as a non-root user. This example packages a small Python web service:

FROM python:3.13-slim

ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
RUN useradd --system --uid 10001 app
USER app

EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "main:app"]

Add a .dockerignore next to it so secrets and clutter never enter the build context:

.git
.env
__pycache__
*.log
node_modules

Use the exec form of CMD (the JSON array) so the process receives stop signals directly. Never put passwords into ENV or ARG; they stay readable in the image history. Pass them at run time instead, or use a BuildKit secret mount during the build.

How do you build and test the image locally?

Build from the folder that holds the Dockerfile, giving the image a name and a version tag, then start it once to see that it works:

cd /srv/src/notes-api
docker build -t notes-api:1.0.0 .
docker image ls notes-api
docker run --rm -p 127.0.0.1:8000:8000 notes-api:1.0.0
curl -s http://127.0.0.1:8000/health

Add --pull to fetch the newest base image, and --no-cache when you want a clean build for a release. docker image history notes-api:1.0.0 shows the size each instruction added, which points you to layers worth trimming. For multi-stage builds, where one stage compiles and a later stage copies only the result, see the language guides such as containerising a Python app and containerising a Node.js app.

How should you tag images?

Tag every release with an exact version and treat latest as a convenience label only. A full image reference has the registry, the namespace, the repository and the tag:

docker tag notes-api:1.0.0 registry.example.net/deploy/notes-api:1.0.0
docker tag notes-api:1.0.0 registry.example.net/deploy/notes-api:1.0
docker tag notes-api:1.0.0 registry.example.net/deploy/notes-api:latest

Tags are just pointers, so one image can carry several of them at no extra disk cost. Many teams also add the short Git commit, for example :1.0.0-3f9c2ab, so they can trace a running container back to its source. On the servers that run the image, pin a specific version, or even the digest shown after a push (@sha256:...), so a later push of the same tag never changes what you deploy without warning.

How do you log in to a registry and push?

Sign in once per registry. Use an access token rather than your account password, and feed it on standard input so it never appears in your shell history:

read -rs REG_TOKEN
echo "$REG_TOKEN" | docker login registry.example.net -u deploy --password-stdin
docker push registry.example.net/deploy/notes-api:1.0.0
docker push registry.example.net/deploy/notes-api:latest

Docker stores the credential in ~/.docker/config.json, only base64 encoded unless a credential helper is configured, so keep that file readable by your user alone (chmod 600) and run docker logout registry.example.net on shared machines. Logging in without a registry name targets Docker Hub. You can also run a private registry yourself with the registry:2 image, bound to 127.0.0.1 and published through a TLS reverse proxy with authentication, for example Caddy.

How do you build for several CPU types with buildx?

Create a builder that uses the docker-container driver, register QEMU emulators, then build every platform in one command. Multi-platform results go straight to the registry with --push:

docker run --privileged --rm tonistiigi/binfmt --install arm64
docker buildx create --name multi --driver docker-container --use
docker buildx inspect --bootstrap

docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t registry.example.net/deploy/notes-api:1.0.0 \
  --push .

docker buildx imagetools inspect registry.example.net/deploy/notes-api:1.0.0

The last command lists one manifest per platform. Emulated ARM builds on an x86 server are noticeably slower, so heavy compile steps may take a while. For a single platform build that you want in the local image list, use --load instead of --push.

Why is docker commit a poor way to make images?

The docker commit command saves the current filesystem of a container as a new image. It works, but the result has no recipe: nobody can see how it was made, rebuild it with a newer base, or review what changed. It also captures whatever happened to be inside, such as shell history, temporary files, caches or credentials typed during a session.

docker commit -m "debug snapshot" web web-debug:2026-12-03
docker diff web

Keep it for short-term needs, like preserving a broken container to investigate later. docker diff is useful beforehand to see which files a container added or changed. For anything you deploy, write the change into the Dockerfile and rebuild.

How do you keep images small and current?

Smaller images pull faster and expose fewer packages. Choose -slim or Alpine based images where the software supports them, combine package install and cache cleanup in one RUN step, and use multi-stage builds so compilers stay out of the final image. Rebuild on a schedule with --pull so base image security fixes reach you, then bump the tag and redeploy. Old local images from those rebuilds are cleared as shown in the cleanup guide.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
F2-4quick NVMe builds for one project2 vCPU, 4 GB RAM, 128 GB NVMe$14.40/mo$43.20 for 3 months
A4-8regular multi-platform builds4 vCPU, 8 GB RAM, 180 GB NVMe$28.80/mo$86.40 for 3 months

Questions about Build, tag and push Docker images

What is the difference between docker build and docker buildx build?

On current Docker Engine both use BuildKit. buildx adds builder instances, multi-platform output and extra export options; plain docker build is enough for single-platform local images.

Why does my push say denied or unauthorized?

Either you are not logged in to that registry, the token lacks write permission, or the image name does not include your namespace. Check the full reference with docker image ls.

Can I build images on a 1 GB server?

Small builds work, but language package installs can run out of memory. Add a swap file or use a plan with more RAM for regular builds.

How do I move an image without a registry?

Use docker save notes-api:1.0.0 | gzip > notes-api.tar.gz, copy the file, and run docker load -i notes-api.tar.gz on the other server.

Should I use the latest tag in production?

It is better to deploy a fixed version tag or digest. latest moves whenever someone pushes, which makes rollbacks and audits harder.