Quick reference
docker run -d --name api -p 8080:80 myapp:1.4| Part | Name | What it means |
|---|---|---|
docker | The client | The Docker CLI, sending your command to the daemon. |
run | The action | Create a new container from an image and start it. |
-d | Detached | Run in the background and print the container ID. |
--name api | A name | So you refer to it as api, not a random hash. |
-p 8080:80 | Port map | Host port 8080 forwards to container port 80. |
myapp:1.4 | The image | Name and tag. Pin a real tag, never latest. |
Explained
docker is the client. It takes your command and sends it to the Docker daemon, which does the real work. That split is why Docker commands can target a remote host too.
run means create a new container from an image and start it. It is really two steps, create and start, in one. If the image is not on the machine, Docker pulls it first.
-d is detached mode. The container runs in the background and Docker prints its ID instead of streaming the logs. Leave it off and your terminal is attached to the container, which is handy for a quick test.
--name api gives the container a readable name. Without it, Docker invents a random one, and every later command has to use the ID. A clear name makes docker logs, docker exec and docker stop much easier.
-p 8080:80 publishes a port. Traffic to port 8080 on the host is forwarded to port 80 inside the container. The order is host:container, and getting it backwards is a classic mistake. For safety, bind to a specific address: -p 127.0.0.1:8080:80.
myapp:1.4 is the image and tag. The tag is the part people skip, and latest is not a version: it is whatever was newest when you pulled. Pin a real tag so the same command gives the same container next month.
In one line
Read the command, know the container. Each flag is a decision you can explain.
See what is running
docker psMore notes: Docker & containers
- P277The Docker command cheat sheet
- P1995 Dockerfile mistakes to avoid
- P196Alpine vs Debian base images
- P1949 docker commands for building and shipping images
- P1649 docker compose commands for daily work
- P163Anatomy of a container image reference
- P152Docker Compose vs Kubernetes
- P147Quiz: 3 container questions
Open in the notes app: search, filters, copy This note on GitHub