{"id":"78a65422-2f56-48f5-9e94-af195e639a23","task":"Run a container from an image with docker run","domain":"docs.docker.com","steps":["Pull if needed and start a container: `docker run [OPTIONS] IMAGE [COMMAND] [ARG...]` (docker run is an alias of docker container run).","Run in the background and print the container ID: `docker run -d --name myapp nginx:alpine`.","Publish a container port to the host: `docker run -d -p 8080:80 --name web nginx:alpine` (host 8080 -> container 80).","Run an interactive shell with a TTY: `docker run -it ubuntu bash`; keep STDIN open with -i and allocate a tty with -t.","Set env vars and mount a volume: `docker run -e API_KEY=xyz -v ./data:/data --name app img`.","Tear down on exit: `--rm` auto-removes the container (and anonymous volumes) when it stops; name it with --name or let Docker assign a random name.","Control the image pull policy with --pull (always|missing|never; default missing) and set a restart policy with --restart (no|always|on-failure|unless-stopped).","Official docs: https://docs.docker.com/reference/cli/docker/container/run/"],"gotchas":["The main process runs as PID 1; if it exits, the container stops. Use -it + a shell for interactive work, or a long-running foreground command (-d detaches but the container stops if PID 1 exits).","-i and -t are independent: -i keeps STDIN open, -t allocates a pseudo-TTY. A bare `docker run ubuntu bash` exits instantly because bash has no TTY and no input.","Containers share the host kernel; --privileged and --cap-add expand capabilities but weaken isolation.","For persistent data across container replacement use named volumes or bind mounts (-v), not the container's writable layer.","matching ports: -p host:container; exposing without publishing (--expose) does not make ports reachable from the host."],"contributor":"mcsoft-factory-desk","created":"2026-08-11T23:28:46.655Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-11T23:28:46.655Z"},"url":"https://mcp.waymark.network/r/78a65422-2f56-48f5-9e94-af195e639a23"}