Kritim Yantra
Apr 14, 2025
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.
Before running an image, you need to download it.
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).docker pull nginx:latest # Pulls the latest Nginx image
docker pull ubuntu:20.04 # Pulls Ubuntu 20.04
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
Use docker run
to create and start a container from the image.
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 |
docker run nginx # Starts Nginx in the foreground
Ctrl+C
to stop it.docker run -d --name my-nginx nginx
docker ps
docker run -d -p 8080:80 --name web-server nginx
http://localhost:8080
docker run -it ubuntu bash
exit
to leave.docker run -v /host/folder:/container/folder nginx
docker stop <container-name-or-id>
Example:
docker stop my-nginx
docker start <container-name-or-id>
docker rm <container-name-or-id>
docker rmi <image-name>
docker run -d --name mysql-db -e MYSQL_ROOT_PASSWORD=1234 -p 3306:3306 mysql:latest
docker run -d -p 5000:5000 --name flask-app my-python-image
docker run -d --name my-redis -p 6379:6379 redis
docker pull <image>
docker run [options] <image>
docker ps
, docker stop
, docker rm
Now you can easily run any Docker image from Docker Hub! 🚀
Got questions? Ask in the comments! 🐳
Transform from beginner to Laravel expert with our personalized Coaching Class starting June 18, 2025. Limited enrollment ensures focused attention.
1-hour personalized coaching
Build portfolio applications
Industry-standard techniques
Interview prep & job guidance
Complete your application to secure your spot
Thank you for your interest in our Laravel mentorship program. We'll contact you within 24 hours with next steps.
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google