1. Creating a Docker Hub Account
Docker Hub is a public registry where you can store and share your Docker images.
Steps to create an account:
- Navigate to: https://hub.docker.com/
- Click on Sign Up and fill in your details.
- Agree to the terms and conditions.
- Verify your email through the confirmation link.
- Log in using your new credentials.
Once you have an account, you can pull images from Docker Hub with: docker pull <image-name>
Example: docker pull ubuntu
2. Committing Changes to a Container
Sometimes, you may need to modify a running container (e.g., installing software) and save it as a new image.
Example: Installing Apache inside an Ubuntu container
- Pull the base image:
docker pull ubuntu - Run the container:
docker run -it -d ubuntu - Access the container:
docker exec -it <container-id> - Inside the container, install Apache:
apt-get update,apt-get install apache2 - Exit the container and commit changes:
docker commit <container-id> <dockerhub-username>/<image-name>
Example: docker commit 4f3b2c1d7e12 mydockeruser/ubuntu-apache
Now you have a custom image ready to be pushed.
3. Pushing the Container Image to Docker Hub
- Log in to Docker Hub from the terminal:
docker login - Push the committed image:
docker push <dockerhub-username>/<image-name> - Verify on Docker Hub: Go to your Docker Hub account, and you'll see the uploaded image.
Anyone can now pull it using:
docker pull mydockeruser/ubuntu-apache
Recap
- Docker Hub lets you store and share images.
- docker commit allows you to save container changes as an image.
- docker push helps you publish your images for reuse.
Mastering these steps is essential for building efficient CI/CD pipelines in any DevOps workflow.