How to Run a Docker Image After Pulling from Docker Hub

Author

Kritim Yantra

Apr 14, 2025

How to Run a Docker Image After Pulling from Docker Hub

After pulling an image from Docker Hub, you can run it as a container using the docker run command. Below is a step-by-step guide with examples.


Step 1: Pull the Image from Docker Hub

Before running an image, you need to download it.

Command:

docker pull <image-name>:<tag>
  • <image-name>: Name of the image (e.g., nginx, ubuntu).
  • <tag>: Version of the image (default is latest if not specified).

Example:

docker pull nginx:latest  # Pulls the latest Nginx image
docker pull ubuntu:20.04  # Pulls Ubuntu 20.04

Verify the Pulled Image

docker images  # Lists all downloaded images

Output:

REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    abc123...      2 weeks ago   133MB
ubuntu       20.04     def456...      3 weeks ago   72.8MB

Step 2: Run the Docker Image

Use docker run to create and start a container from the image.

Basic Syntax:

docker run [options] <image-name>

Common options:

Option Description
-d Run in detached (background) mode
-p <host-port>:<container-port> Map host port to container port
--name <container-name> Assign a custom name to the container
-it Interactive mode (for shells like bash)
-v <host-path>:<container-path> Mount a volume

Examples:

1. Run a Simple Container

docker run nginx  # Starts Nginx in the foreground
  • Press Ctrl+C to stop it.

2. Run in Detached Mode (Background)

docker run -d --name my-nginx nginx
  • Check running containers:
    docker ps
    

3. Expose a Port (e.g., Nginx on Port 8080)

docker run -d -p 8080:80 --name web-server nginx
  • Access Nginx at:
    http://localhost:8080
    

4. Run an Interactive Shell (e.g., Ubuntu)

docker run -it ubuntu bash
  • This opens a shell inside the container.
  • Type exit to leave.

5. Mount a Volume (Persistent Storage)

docker run -v /host/folder:/container/folder nginx

Step 3: Managing the Running Container

Stop a Container

docker stop <container-name-or-id>

Example:

docker stop my-nginx

Start a Stopped Container

docker start <container-name-or-id>

Remove a Container

docker rm <container-name-or-id>

Remove an Image

docker rmi <image-name>

Common Use Cases

1. Running a MySQL Database

docker run -d --name mysql-db -e MYSQL_ROOT_PASSWORD=1234 -p 3306:3306 mysql:latest

2. Running a Python Flask App

docker run -d -p 5000:5000 --name flask-app my-python-image

3. Running Redis (In-Memory Database)

docker run -d --name my-redis -p 6379:6379 redis

Conclusion

  • Pull an imagedocker pull <image>
  • Run itdocker run [options] <image>
  • Manage containersdocker ps, docker stop, docker rm

Now you can easily run any Docker image from Docker Hub! 🚀

Got questions? Ask in the comments! 🐳

LIVE MENTORSHIP ONLY 5 SPOTS

Laravel Mastery
Coaching Class Program

KritiMyantra

Transform from beginner to Laravel expert with our personalized Coaching Class starting June 18, 2025. Limited enrollment ensures focused attention.

Daily Sessions

1-hour personalized coaching

Real Projects

Build portfolio applications

Best Practices

Industry-standard techniques

Career Support

Interview prep & job guidance

Total Investment
$200
Duration
30 hours
1h/day

Enrollment Closes In

Days
Hours
Minutes
Seconds
Spots Available 5 of 10 remaining
Next cohort starts:
June 18, 2025

Join the Program

Complete your application to secure your spot

Application Submitted!

Thank you for your interest in our Laravel mentorship program. We'll contact you within 24 hours with next steps.

What happens next?

  • Confirmation email with program details
  • WhatsApp message from our team
  • Onboarding call to discuss your goals

Tags

Comments

No comments yet. Be the first to comment!

Please log in to post a comment:

Sign in with Google

Related Posts