How to build and push Docker image with tags?

To build and push a Docker image with tags, you can use the docker build and docker push commands.

Here is an example of how to build and push a Docker image with tags:

docker build -f ./8.1/apache/Dockerfile -t krizius/php:8.1-apache .

This will build the Docker image and tag it as krizius/php:8.1-apache. The . at the end specifies the current directory as the build context.

With this example I am buildin image of PHP that are free to use.

If you want to add additional tags to the image, you can use the -t flag multiple times:

docker build -t myimage:latest -t myimage:1.0 .

This will build the Docker image and tag it as both myimage:latest and myimage:1.0.

Once the Docker image is built, you can push it to a registry such as Docker Hub using the docker push command:

docker push myimage:latest

This will push the myimage:latest tag to the registry. If you want to push the other tags as well, you can use the docker push command multiple times:

docker push myimage:latest
docker push myimage:1.0

Keep in mind that you need to be logged in to the registry in order to push the image. You can use the docker login command to log in to a registry.

I hope this will help you and enjoy your work with Docker.

Tags: #docker , Created: 31. 12. 2022
Created by Martin Krizan (2024)