This tutorial is aimed to show you how to build and push an image to the Docker Hub repo. Let’s jump on the steps bellow.
Prerequisites
- Docker
- Docker Hub account
- sudo privileges
Build and push the image
Step 1. First, 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
: Repository name.$IMAGE_TAG
: Image tag.
Step 3. After building the image the next thing is to push the image to your Docker Hub repo and execute the docker push
command.
sudo docker push $DOCKER_ACCOUNT/$DOCKER_REPO:$IMAGE_TAG
Conclusion
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 CI/CD tools. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.