Phase 3 — Deploy & Use · Step 10 of 14

RUN — Generate a Container from an Image

Running an image creates a live instance of it called a container. The docker run command is the most direct way to start a container.

How docker run Works

When you run docker run <image>:

  1. Docker checks if the image exists locally.
  2. If not, it automatically pulls it from Docker Hub.
  3. 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

FlagMeaning
-dDetached — run in background
-p 9000:9000Map host port 9000 → container port 9000
--name=portainerGive the container a human-readable name
--restart=alwaysAutomatically restart after reboot or crash
-v /var/run/docker.sock:…Mount Docker socket so Portainer can control Docker
-v portainer_data:/dataPersist 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