Deploying a Docker Image to Docker Hub
Every time we run docker build
, the image created is locally available. Normally, the Dockerfile is hosted together with the code base; therefore, on a new machine, one would need to use docker build
to create the Docker image.
With Docker Hub, any developer has the opportunity to have a Docker image hosted to be pulled into any machine running Docker. This does two things:
- Eliminates the repetitive task of running
docker build
- Adds an additional way of sharing your application which is simple to set up compared to sharing a link of your app's code base and README detailing the setup process
docker login
is the command to run to connect to Docker Hub via the CLI. You need to have an account in hub.docker.com and enter the username and password through the terminal.
docker push <docker-hub-username/image-name[:tag]>
is the command to send the image to the registry, Docker Hub:
A simple search of your image on hub.docker.com will give the output to your Docker image.
In a new machine, a simple docker pull <docker-hub-username/your-image-name>
command will produce a copy of your image locally.