wiki:docker-running
Table of Contents
Docker Running containers
Running a container starts an instance from an image. Use docker run <image> to start; add -it for interactive (attach a terminal), -d to run in background, --name <name> to give it a name. The container stops when its main process exits.
$ docker run -it ubuntu bash # interactive, exit to stop $ docker run -d --name web nginx # background, stays until stopped $ docker run -e VAR=value myapp # set environment variables $ docker run -p 8080:80 myapp # map ports (host:container) $ docker run -v /host:/container myapp # mount a volume
Flags stack: docker run -it -d --name foo -e X=1 -p 8080:80 image. Use docker ps to list running containers, docker logs to see output, and docker exec to run commands inside. Stopping a container with docker stop sends SIGTERM; it waits briefly, then sends SIGKILL.
wiki/docker-running.md · Last modified: (external edit)
