Command referencedocker
docker command (Linux / bash / sh / zsh)
What it does
Build images and manage containers, networks, and volumes. When people search for the docker command linux containers, they usually want docker's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.
Build images and manage containers, networks, and volumes.
Syntax
docker [OPTION] COMMAND [ARG...]
Common options
| Flag / option | Meaning |
|---|---|
| run | Create and start a container. |
| ps | List containers. |
| build | Build an image from a Dockerfile. |
| logs | Fetch container logs. |
| exec | Run a command in a running container. |
Practical examples
Run web server
docker run --rm -p 8080:80 nginx
Starts nginx and maps local port 8080.
List running
docker ps
Shows active containers.
Follow logs
docker logs -f api
Streams logs from container api.
Common mistakes
- Publishing a container port to all interfaces unintentionally.
- Using mutable `latest` tags where reproducible deployments require pinned versions.
Related commands
FAQ
What does docker do in Linux?
Build images and manage containers, networks, and volumes.
How do I use docker from the terminal?
Start with `docker [OPTION] COMMAND [ARG...]`, then choose only the options needed for the task.
What is a practical docker example?
Try `docker run --rm -p 8080:80 nginx` — Starts nginx and maps local port 8080.
Can I use docker in a shell script?
Yes. docker works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.