🚢 Mastering Docker: Build and Share Your First Container Image on DockerHub
Funmilola Elizabeth Musari

Funmilola Elizabeth Musari @betty_babs_f40c2ed0166cb7

About: Cloud learner & DevOps storyteller 🎙️ | Betty Musari ✨ | Turning troubleshooting into gist-worthy lessons 💻 | Docker • Kubernetes • AWS • Azure

Location:
Lagos, Nigeria
Joined:
Aug 18, 2025

🚢 Mastering Docker: Build and Share Your First Container Image on DockerHub

Publish Date: Aug 18
0 0

Introduction

Welcome, future Docker pro! 🐳 Have you ever wondered how developers share applications in lightweight, portable containers? Or how to deploy the same environment from your laptop to a server in seconds? The answer lies in Docker images.

In this guide, you’ll learn:

✔ How to build a Docker image from a Dockerfile

✔ Push it to DockerHub (shareable anywhere!)

✔ Modify and update your image


Key Concepts

1. What’s a Container?

A container is a lightweight, standalone package that includes:

  • OS-level virtualization (only the essentials, not the whole OS)
  • Isolated dependencies (no more "works on my machine" issues)
  • Portability (runs identically on any system)

Common Use Cases

  • Running microservices
  • CI/CD pipelines
  • Ensuring dev/production parity
  • Building scalable architectures

2. What’s a Docker Image?

A read-only template to create containers. Includes:

  • Your application code
  • Libraries/dependencies
  • Configuration files

Popular Base Images:

ubuntu  # Minimal OS
nginx   # Web server
python  # Python apps
redis   # Database
Enter fullscreen mode Exit fullscreen mode

3. What’s DockerHub?

A cloud registry to store/share Docker images. Alternatives:

  • Azure Container Registry
  • Google Container Registry
  • Amazon ECR

Prerequisites

  1. Docker installed (Install guide)
  2. DockerHub account (Sign up)

Step-by-Step Guide

Step 1: Update System Packages

sudo su
apt update && apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Step 2: Create a Project Directory

mkdir mydockerproject
cd mydockerproject
Enter fullscreen mode Exit fullscreen mode

Step 3: Create a Dockerfile

vi Dockerfile
Enter fullscreen mode Exit fullscreen mode

Paste this (press i to insert, ESC + :wq to save):

FROM ubuntu:latest
RUN apt update && apt install -y nginx
CMD ["echo", "Hello from your first Docker container!"]
Enter fullscreen mode Exit fullscreen mode

Step 4: Build the Image

docker build -t mydocker .
Enter fullscreen mode Exit fullscreen mode

Verify:

docker image ls  # Lists all images
docker run --rm mydocker  # Test the container
Enter fullscreen mode Exit fullscreen mode

Step 5: Create a DockerHub Repository

  1. Go to DockerHub.
  2. Click "Create Repository".
  3. Name it (e.g., mydocker-image), set visibility to Public, and add a description.

Step 6: Push to DockerHub

6.1 Log in to DockerHub

docker login
Enter fullscreen mode Exit fullscreen mode

6.2 Tag Your Image

docker tag mydocker yourusername/repositoryname:tag
Enter fullscreen mode Exit fullscreen mode

6.3 Push the Image

docker push yourusername/repositoryname:tag
Enter fullscreen mode Exit fullscreen mode

Verify: Refresh your DockerHub repository—your image should appear!


🛠️ Updating Your Image

1. Modify the Dockerfile

Example changes:

RUN apt update && apt install -y curl  # Added curl
CMD ["echo", "Welcome to Docker!"]    # Updated message
Enter fullscreen mode Exit fullscreen mode

2. Rebuild with a New Tag

docker build -t yourusername/repositoryname:newtag .
Enter fullscreen mode Exit fullscreen mode

3. Push the Updated Image

docker push yourusername/repositoryname:newtag
Enter fullscreen mode Exit fullscreen mode

Next Steps

  • Pull the image elsewhere: docker pull yourusername/repositoryname:tag
  • Explore multi-stage builds for smaller images.
  • Learn Docker Compose for multi-container apps.

🎉 Conclusion

You’ve now mastered:

✅ Building Docker images

✅ Sharing them via DockerHub

✅ Updating images efficiently

Happy Dockering! 🐋✨

Comments 0 total

    Add comment