Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
org
ryanwhocodes Follow
Oct 1, 2018 · 4 min read
https://medium.freecodecamp.org/dockers-detached-mode-for-beginners-c53095193ee9 1/7
3/13/2019 Docker’s detached mode for beginners – freeCodeCamp.org
• Detached mode
• View containers
• Attach
Detached mode
When starting a Docker container, you must first decide if you want to
run the container in the background in a detached mode or in the
default foreground mode. You may want to use this if you want a
container to run but do not want to view and follow all its output.
You will often see the short version of the detach option used, -d ,
while the longer version is --detach .
If you run containers in detached mode, you may then need to check on
their status or run commands on them. Next, I will explain how to view
them in your terminal.
View containers
Once you have started your containers in detached mode, you can view
them running using the CLI command docker ps .
• --quiet / -q to list their ids (useful for when you want to get all
the containers).
To see even more information about a container you can view its logs.
https://medium.freecodecamp.org/dockers-detached-mode-for-beginners-c53095193ee9 2/7
3/13/2019 Docker’s detached mode for beginners – freeCodeCamp.org
• --tail While the default is all lines, you can specify a specific
number of lines to show from the end of the logs.
As well as viewing container output this way, you can also run commands
to reattach your terminal input and output to the container.
For example, you might want use docker exec with the -i
https://medium.freecodecamp.org/dockers-detached-mode-for-beginners-c53095193ee9 3/7
3/13/2019 Docker’s detached mode for beginners – freeCodeCamp.org
Here are a few links to my other posts where I explain docker exec
further.
You may even want to attach your terminal again to view a container’s
output. Next, I will show you how you can do this.
Attach
The docker attach command connects your terminal’s standard
input, output and error to a running container by passing it the
container name or ID.
https://medium.freecodecamp.org/dockers-detached-mode-for-beginners-c53095193ee9 4/7