Docker Kata 2: Disconnected Containers
Explore how to run Docker containers in the background using detached mode, execute commands within running containers, and manage container logs and network settings. This lesson helps you understand container lifecycle, interaction, and monitoring to effectively manage Docker environments.
The first kata demonstrated containers that exit immediately after they’re run. This kata will teach us how to run a container that continues running in the background after executing the docker container run command.
Step 1: Run a disconnected container
The command to run a disconnected container in the background is given below.
The output will be something like this:
Commands
Parameter | Description |
| This is the parent command. |
| This is the command that runs a container from an image. |
| The |
| This is the name of the image to run; in this case, the Ubuntu Linux image. |
| This is the command to run inside the container when it starts. This is the shell, which can run commands and scripts. |
| The |
| This is the script to be run by the shell:
|
This step demonstrates how Docker can run a disconnected container in the background. Running a disconnected container is essentially the opposite of running it interactively. A disconnected container will run without user input or interaction as long as its start process runs.
This command does the following:
- Runs a disconnected Ubuntu container
- Specifies the command to run after the image name
- Uses
/bin/shto run theshshell, which runs scripts in the bash command language - Executes the inline script:
"while true; do echo hello docker; sleep 1; done"
When this command is run, there’s one output, which is the ID of the started container. The Unix shell program bin/sh acts as the start command. The inline ...