Running Your First Container
Running Your First Container
Now that you understand images and containers, it’s time to run one!
Example: The “Hello World” of Docker
The simplest way to verify your Docker installation and learn the workflow is by running the hello-world image.
Run this command in your terminal:
docker run hello-world
What Happens Behind the Scenes?
When you run docker run hello-world, Docker follows these steps:
- Check Locally: Docker looks for the
hello-worldimage on your computer. - Download (Pull): If it’s missing, it automatically downloads it from Docker Hub.
- Create: Docker creates a new container based on that image.
- Run: The container starts and runs a simple program that prints “Hello from Docker!”
- Exit: The program finishes, and the container stops.
Visualization
docker run hello-world
↓
Pull image from Docker Hub
↓
Create container
↓
Run program