Docker Containers Workflow
We’ll look at containers in detail in this chapter.
docker top
A container’s top processes can be seen with this command.
Syntax
$ docker top ContainerID Example
$ sudo docker top bcdbe9ff7eoeOutput
As a result of the above command:

docker stop
Stopping a running container with this command.
Syntax
$ docker stop ContainerID Example
$ sudo docker stop bcdbe9ff7eoe
This command stops the Docker container of ID bcdbe9ff7eoe.
Output
We’ll get the following result when we run the above command

docker rm
You can delete a container with this command.
Syntax
$ docker rm ContainerID Options
- ContainerID − Remove this Container ID.
Return Value
You’ll get the ID of the removed container in the output.
Example
$ sudo docker rm bcdbe9ff7eoe You can remove the Docker container bcdbe9ff7eoe with this command
Output
As a result of running the command above, we will see the following results:

docker stats
Stats about a running container are provided by this command.
Syntax
$ docker stats ContainerID Options
- ContainerID − This is the Container ID you need to provide stats for.
Return Value
In the output, you’ll see how much CPU and memory the container is using.
Example
$ sudo docker stats 0a67bele8784
This command will show you how much CPU and memory the Container 0a67bele8784 is using.
Output
The above command will produce the following result:

docker attach
Attach to a running container with this command.
Syntax
$ docker attach ContainerID Options
- ContainerID − The Container ID you need to attach.
Example
$ sudo docker attach 0a67bele8784 This will attach to Docker container 0a67bele8784.
Output
We’ll get the following result when we run the above command

docker pause
In a running container, this command pauses the processes.
Syntax
$ docker pause ContainerID Example
$ sudo docker pause 9f7c866a9be8. By running the above command, you’ll pause the processes in the container 9f7c866a9be8.
Output
We’ll get the following result when we run the above command

docker unpause
You use this command to unpause running processes.
Syntax
$ docker unpause ContainerIDOptions
- ContainerID − This is the Container ID where you need to unpause the processes.
Example
$ sudo docker unpause 9f7c866a9be8 You can unpause processes in a running container with this command: 9f7c866a9be8.
Output
We’ll get the following result when we run the above command

docker kill
A container’s processes can be killed with this command.
Syntax
$ docker kill ContainerIDExample
$ sudo docker kill 9f7c866a9be8.
By running the above command, the processes in container 9f7c866a9be8 will be killed.
Output
We’ll get the following result when we run the above command

Docker – Containers Lifecycle
Here’s an illustration of Docker’s entire lifecycle.

- The Docker container will start out in the created state.
- When you run Docker, the container goes into running mode.
- Docker kill kills an existing Docker container.
- Docker pause pauses an existing Docker container.
- A Docker stop pauses an existing container.
- Putting a container back into a running state with Docker run.