Open an interactive bash shell inside the running nginx1 container.
docker exec -it nginx1 bash
-i = interactive, -t = allocate a TTY. Use sh instead of bash for Alpine-based images. Exit with Ctrl+D or exit.
Safety: Inspect state before stopping, pruning, or changing running containers.
Run a one-off command (nginx config test) inside the nginx1 container without opening a shell.
docker exec nginx1 nginx -t
docker exec runs a one-off command in a running container. No -it needed for non-interactive commands. The exit code propagates to your shell.
Safety: Inspect state before stopping, pruning, or changing running containers.
Build the habit: DockerDrill drills docker exec and the rest of the Docker workflow until the safe first move is automatic. Try a Docker drill.