In this chapter, we will explore in detail what we can do with containers.
With this command, you can see the top processes within a container.
docker top ContainerID
ContainerID − This is the Container ID for which you want to see the top processes.
The output will show the top-level processes within a container.
sudo docker top 9f215ed0b0d3
The above command will show the top-level processes within a container.
When we run the above command, it will produce the following result −
This command is used to stop a running container.
docker stop ContainerID
ContainerID − This is the Container ID which needs to be stopped.
The output will give the ID of the stopped container.
sudo docker stop 9f215ed0b0d3
The above command will stop the Docker container 9f215ed0b0d3.
When we run the above command, it will produce the following result −
This command is used to delete a container.
docker rm ContainerID
ContainerID − This is the Container ID which needs to be removed.
The output will give the ID of the removed container.
sudo docker rm 9f215ed0b0d3
The above command will remove the Docker container 9f215ed0b0d3.
When we run the above command, it will produce the following result −
This command is used to provide the statistics of a running container.
docker stats ContainerID
ContainerID − This is the Container ID for which the stats need to be provided.
The output will show the CPU and Memory utilization of the Container.
sudo docker stats 9f215ed0b0d3
The above command will provide CPU and memory utilization of the Container 9f215ed0b0d3.
When we run the above command, it will produce the following result −
This command is used to attach to a running container.
docker attach ContainerID
ContainerID − This is the Container ID to which you need to attach.
None
sudo docker attach 07b0b6f434fe
The above command will attach to the Docker container 07b0b6f434fe.
When we run the above command, it will produce the following result −
Once you have attached to the Docker container, you can run the above command to see the process utilization in that Docker container.
This command is used to pause the processes in a running container.
docker pause ContainerID
ContainerID − This is the Container ID to which you need to pause the processes in the container.
The ContainerID of the paused container.
sudo docker pause 07b0b6f434fe
The above command will pause the processes in a running container 07b0b6f434fe.
When we run the above command, it will produce the following result −
This command is used to unpause the processes in a running container.
docker unpause ContainerID
ContainerID − This is the Container ID to which you need to unpause the processes in the container.
The ContainerID of the running container.
sudo docker unpause 07b0b6f434fe
The above command will unpause the processes in a running container: 07b0b6f434fe
When we run the above command, it will produce the following result −
This command is used to kill the processes in a running container.
docker kill ContainerID
ContainerID − This is the Container ID to which you need to kill the processes in the container.
The ContainerID of the running container.
sudo docker kill 07b0b6f434fe
The above command will kill the processes in the running container 07b0b6f434fe.
When we run the above command, it will produce the following result −
The following illustration explains the entire lifecycle of a Docker container.
Initially, the Docker container will be in the created state.
Then the Docker container goes into the running state when the Docker run command is used.
The Docker kill command is used to kill an existing Docker container.
The Docker pause command is used to pause an existing Docker container.
The Docker stop command is used to pause an existing Docker container.
The Docker run command is used to put a container back from a stopped state to a running state.