DEV Community

VASHANTHA KUMAR K.S
VASHANTHA KUMAR K.S

Posted on

πŸš€ Docker Image Creation and Pushing to DockerHub: Step-by-Step Guide

πŸ› οΈ Step 1: Install Docker
First, ensure Docker is installed on your machine.
You can install Docker Desktop from https://docs.docker.com/get-docker/.

Check if Docker is installed correctly:


docker --version

πŸ› οΈ Step 2: Create a Simple Application
Let's create a simple app. For example, a basic Python app.

Create a folder and files:

mkdir my-docker-app
cd my-docker-app
touch app.py
app.py:


print("Hello, Docker World!")

πŸ› οΈ Step 3: Create a Dockerfile
Inside the same folder, create a Dockerfile:
touch Dockerfile

Dockerfile content:

`FROM python:3.10-slim

WORKDIR /app

COPY . .

CMD ["python", "app.py"]

πŸ› οΈ Step 4: Build the Docker Image
Now, build the image using:

docker build -t your_dockerhub_username/my-docker-app:latest .

Note: Replace your_dockerhub_username with your actual DockerHub username.

πŸ› οΈ Step 5: Run the Docker Container
Test your image by running:

docker run your_dockerhub_username/my-docker-app:latest

You should see:

Hello, Docker World!

πŸ› οΈ Step 6: Login to DockerHub
Before pushing the image, log in to your DockerHub account:

docker login

Enter your username and password when prompted.

πŸ› οΈ Step 7: Push the Image to DockerHub
Now, push your image:

docker push your_dockerhub_username/my-docker-app:latest
After successful push, you can visit:
πŸ‘‰ https://hub.docker.com/
and find your repository under your profile.

πŸ› οΈ Bonus: Pulling and Running the Image from Any Machine
Anyone (including you) can pull and run your image using:

docker pull your_dockerhub_username/my-docker-app:latest
docker run your_dockerhub_username/my-docker-app:latest

πŸ“Œ Conclusion
That's it!
You have successfully:

Created a Docker image

Tested it locally

Logged into DockerHub

Pushed your image to DockerHub!

Now your app can be shared globally or deployed to production. πŸš€

Image description

Image description

Image description

Top comments (0)