How are docker commands structured, and what do the flags -i, -t, -d, --name and -p do in docker container run -itd --name web-server-nginx -p 8080:80 nginx:latest?
docker <object> <action> <flags> <image|name|ID>; here: keep STDIN open, allocate a terminal, run in the background, name it, and publish container port 80 on host port 8080.
Most commands follow the pattern docker <what for> <what to do> <flags> <target>: docker container run …, docker image pull nginx, docker network ls, docker volume inspect myvolume. Many have short forms (docker run = docker container run, docker ps = docker container ls).
| Flag | Meaning |
|---|---|
-i |
Interactive: keeps STDIN open, so input can be sent to the container. |
-t |
TTY: allocates a pseudo-terminal. Together with -i you get a usable shell in the container. |
-d |
Detached: the container runs in the background and your terminal stays on the host. |
--name web-server-nginx |
A readable name instead of the random one; without it you would address the container by its ID (a unique prefix of it is enough). |
-p 8080:80 |
Publishes a port: host port 8080 forwards to container port 80, where nginx listens. |
The last argument is the image to start, nginx:latest. If it is not available locally, Docker pulls it first. Afterwards docker container ps -a lists all containers (running and stopped) with their port mappings, and http://localhost:8080 shows the nginx welcome page.
Go deeper:
Docker Docs: docker container run — every option of
run, including-i,-t,-dand-p.