Introduction

In this guide, we’ll learn how to build a Docker image, push it to Docker Hub, and run it from anywhere.
Docker makes it easy to package your applications and run them on any system without worrying about dependencies. We’ll create a basic NGINX app, containerize it, and show you how to share it using Docker Hub. If you’re new to Docker or want a quick project to get hands-on, this is the perfect place to start.
Prerequisites
✅ Docker installed on your machine
👉 Follow this guide to install Docker on Ubuntu https://freedevopsonline.com/how-to-install-docker-on-ubuntu-step-by-step-with-script-2025-guide/
✅ A Docker Hub account
👉 Sign up at hub.docker.com
Step 1 – Create a Sample App and Dockerfile
To get started, we’ll create a simple static web application using Nginx and host an index.html file inside it. This is perfect for testing Docker image creation and pushing it to Docker Hub.
Create a New Project Directory.Open your terminal and run:
mkdir docker-test && cd docker-test
Now, inside this directory, create a file named Dockerfile with the following content:
Create a Dockerfile
FROM nginx:alpine
COPY ./index.html /usr/share/nginx/html/index.html
Breakdown of the Dockerfile:
FROM nginx:alpine
This tells Docker to use the lightweight Alpine version of the official Nginx image as the base. It’s optimized and fast for containerized environments.
COPY ./index.html /usr/share/nginx/html/index.html
This line copies your custom index.html from your local folder into the Nginx container’s default web directory. That means when the container runs, it will serve your custom HTML page.
Create index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello Guys</title>
</head>
<body>
<h1>Free Devops Online!</h1>
</body>
</html>
This is the webpage Nginx will serve when your container is running.

Step 2 – Build the Docker Image
Now that you’ve created your Dockerfile and HTML file, it’s time to build Docker image.
docker build -t yourdockerhubusername/nginx:v1 .

Step 3 – Login to Docker Hub
Before we can push our Docker image to Docker Hub, we need to log in to your Docker account from the terminal. Docker Hub is a cloud-based registry where you can store and share your Docker images with others — or keep them private.
docker login -u freedevopsonline

Step 4 – Push Image to Docker Hub
Now that we’re logged in to Docker Hub and have built your image, it’s time to push the image to your Docker Hub repository. This allows you to share your container image with others or use it on different servers and environments.
docker push freedevopsonline/nginx:v1

Step 5 – Pull and Run From Anywhere
Once Docker image is on Docker Hub, you can pull and run it from any machine that has Docker installed.
docker pull freedevopsonline/nginx:v1
docker run -d -p 8080:80 freedevopsonline/nginx:v1

We can test by running localhost:8080

Conclusion
In this guide, we walked through the complete process of building, pushing, and running a Docker image using Docker Hub. From creating a simple NGINX-based app to pushing it to Docker Hub and pulling it from anywhere — you now have the foundational knowledge to build portable, shareable containerized applications.
New to Docker? 👉 Follow this step-by-step guide to install Docker on Ubuntu before starting How to Install Docker on Ubuntu (Step-by-Step with Script) [2025 Guide]