How docker run Works
When you run docker run <image>:
- Docker checks if the image exists locally.
- If not, it automatically pulls it from Docker Hub.
- A new container is created from the image and started.
Single-node only — not Swarm-aware:
docker run starts a container on the current node only. It does not participate in Swarm load balancing, overlay networking or cross-node distribution. Use it to verify an image works before adding it to your stack definition. The production deployment across all four nodes uses docker stack deploy.
Example — Run Portainer
Start Portainer container
$ docker volume create portainer_data
$ docker run -d \
-p 9000:9000 \
--name=portainer \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce
Flag Explanation
| Flag | Meaning |
|---|---|
-d | Detached — run in background |
-p 9000:9000 | Map host port 9000 → container port 9000 |
--name=portainer | Give the container a human-readable name |
--restart=always | Automatically restart after reboot or crash |
-v /var/run/docker.sock:… | Mount Docker socket so Portainer can control Docker |
-v portainer_data:/data | Persist Portainer data to a named volume |
Verify Running Containers
List running containers
$ docker container ls
CONTAINER ID IMAGE COMMAND STATUS PORTS NAMES
ec7630dfd9ac netdata/netdata:latest "/usr/sbin/run.sh" Up 6 minutes 19999/tcp jlar_netdata.1...
3ddb5522d5d0 portainer/portainer-ce "/portainer" Up 2 hours 0.0.0.0:9000->9000/tcp portainer
Use
docker logs <container-name> to see the container's stdout/stderr output. Add -f to follow the log in real time.Full command reference: docs.docker.com — docker run