This tutorial is aimed to show you how to build and push an image to the DockerHub repo. Let’s jump on the steps bellow.
- Docker installed
- Docker Hub account
Build and push the image
Step 1. Firstly, you need to login to your Docker Hub account and execute the
docker login command:
sudo docker login --username=dockerhubusername --password=dockerhubpassword
Step 2. You can build the image with the
docker build command:
sudo docker build -t $DOCKER_ACCOUNT/$DOCKER_REPO:$IMAGE_TAG .
- $DOCKER_ACCOUNT - Name of your account
- $DOCKER_REPO - Repo name
- $IMAGE_TAG - Your tag
Step 3. After building the image the next thing is to push the image to your DockerHub repo and execute the
docker push command:
sudo docker push $DOCKER_ACCOUNT/$DOCKER_REPO:$IMAGE_TAG
Knowing how to build and push an image to Docker Hub is a good practice, especially when you are doing an automatic deployment of your app using some of the CI/CD tools. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on telegram.