Detached Containers
Part of the Introduction to Docker section of Coddy's Terminal journey — lesson 13 of 40.
Some images run long-lived services (a web server, a database) rather than a quick command. You start those in the background with the -d (detached) flag:
docker run -d --name web nginxInstead of streaming the container's output, Docker prints the container's ID and returns control to you straight away. The container keeps running in the background.
To see all the containers that are currently running, use docker ps:
docker psEach row shows the container ID, the image, the command, the status, and the name.
Challenge
EasyStart a detached nginx container named site, then run docker ps to confirm it is running.
Cheat sheet
Run a container in the background with -d (detached) and assign it a name with --name:
docker run -d --name web nginxList all running containers:
docker psTry it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Introduction to Docker
4Managing Containers
Naming ContainersDetached ContainersListing All ContainersStopping And RemovingRecap - Container Lifecycle