Running your first Docker container teaches you something no amount of reading about Docker does what the pull-run cycle actually looks like and what a container’s lifecycle means in practice.
Here’s how it works.
The Pull-Run Cycle
When you run a container, Docker does two things in sequence: it finds the image, then it runs it. The docker run The command handles both in one step.
docker run hello-world
The first time you run this, Docker checks your local machine for the hello-world image. It isn’t there, so Docker pulls it from Docker Hub automatically. Then it creates a container from that image, runs it, and the container prints a message and exits.
That sequence check locally, pull if missing, run happens every time you use docker run. Once an image is on your machine, the pull step is skipped.
What Just Happened
Check the state of your containers after that run:
docker ps -a
The -a flag shows all containers, including stopped ones. You’ll see hello-world listed with a status of Exited (0). It ran, finished, and stopped.
This is the container lifecycle in its simplest form: created, ran, exited. A container runs as long as its main process runs. Hello-world’s process printed a message and finished, so the container finished too. That’s not a failure, that’s exactly correct behaviour.
Running a Real Service
Most containers you’ll actually use run services that stay up on a web server, an AI model, and a database. Those need to run in the background so your terminal stays free.
docker run -d --name my-nginx -p 8080:80 nginx
-d runs it in the background so your terminal stays free, --name my-nginx gives it a readable name instead of Docker’s random one, and -p 8080:80 maps your machine’s port 8080 to the container’s port 80.
Verify it’s running:
docker ps
This time, you’ll see the container listed as Up. Open a browser at http://localhost:8080 And you’ll see the Nginx welcome page, a web server running inside a container, serving pages on your machine.
The Essential Commands
Four commands cover most of what you’ll do with containers day to day:
docker ps # show running containers
docker ps -a # show all containers including stopped
docker stop my-nginx # stop a running container
docker rm my-nginx # remove a stopped container
Stop before removing. Docker won’t let you remove a running container without the force flag, which is a useful guardrail.
Check the logs for any container at any time:
docker logs my-nginx
This is where you go first when something isn’t behaving as expected.
Images vs Containers
An image is the blueprint, static, that sits on your disk. A container is a running instance of that image. The distinction matters because you covered both in detail in earlier posts; this is just the first time you’re seeing them work together in practice.
The Takeaway
The pull-run cycle is the foundation on which everything else builds: Docker finds the image, creates a container, runs it, and the container lives as long as its process does. Services run detached in the background and stay up until you stop them. Understanding the difference between an image and a container is what makes the next step, defining multi-container stacks with Compose, make sense.
