From Dockerfile to Distroless - Container LabStep 9 of 12: Pushing an image to a container registry
All Labs

Pushing an image to a container registry

At this point, our containers are only stored on our machine. To distribute our containers and make them usable from other machines or platforms, it is necessary to push them to a container-registry. Think about such a registry as an artifact-store where you would store your jar files, npm packages or similar with the only difference that this is for containers.

There are many container registries out there, two very prominent examples are Docker Hub (https://hub.docker.com) or the GitHub Container Registry (ghcr).

Before you can push something to the container registries, you have to log in on the corresponding registry at the command line. Please refer to the documentation of your container registry to find out how to log in.

To be able to push a container to the container registry, you have to tag it properly. You'll need to tag the image appropriately for your registry. For example, with GHCR:

docker build -t ghcr.io/tsclabs-eu/lab-container-basics/learning-app:v1.0 .

This command should look pretty familiar to you and the build command should run as we saw it in the rest of the lab. After this has been finished, you can push the image to the repository using the command:

docker push ghcr.io/tsclabs-eu/lab-container-basics/learning-app:v1.0
Troubleshooting

If you get an authentication error, check you're logged in with:

docker login ghcr.io or

docker login docker.io

This command pushes the container to the registry, so it should be usable from there. Take a look at the User Interface of your container registry to find out if everything worked.