☰ See All Chapters |
Docker attached vs detached mode
You can run container in attached mode (in the foreground) or in detached mode (in the background).
By default, Docker runs the container in attached mode. In the attached mode, Docker can start the process in the container and attach the console to the process’s standard input, standard output, and standard error.
Detached mode, started by the option --detach or –d flag in docker run command, means that a Docker container runs in the background of your terminal. It does not receive input or display output. Using detached mode also allows you to close the opened terminal session without stopping the container.
docker run -d [docker_image] |
While running a container in the foreground is that you cannot access the command prompt anymore, as you can see from the screenshot below. Which means you cannot run any other commands while the container is running. In the first screenshot we run in detached mode, in the second screenshot we run in attached mode.
docker run -d --name springbootappcontainer -p 8080:8080 springbootapp |
docker run --name springbootappcontainer -p 8080:8080 springbootapp |
docker attach
To reattach to a detached container, use docker attach command.
docker attach <nameofcontainer> OR docker attach <dockerid> |
All Chapters