Docker

Docker Container

Docker Container

Docker Container is a running instance of a Docker Image or Containers are the ready applications created from Docker Images and they hold the entire package needed to run the application. This happens to be a definitive utility of Docker. Want to read more about Docker Hub?

The business standard today is to utilize Virtual Machines (VMs) to run programming applications. VMs run applications inside a guest Operating System, which keeps running on virtual hardware powered by the server’s host Operating System.

VMs are incredible at giving full procedure separation to applications: there are not many ways an issue in the host operating system can influence the software running in the guest operating system, and the other way around. Be that as it may, this isolation comes at an incredible expense — the computational overhead spent virtualizing hardware for a guest OS to utilize is generous.

Containers adopt an alternate strategy: by utilizing the low-level mechanics of the host operating system, containers give the greater part of the isolation of virtual machines at a small amount of the computing power. Want to read more about Docker Documentation?

 

Why use containers?

Compartments offer a logical packaging mechanism in which applications can be preoccupied from the environment in which they really run. This decoupling permits container-based applications to be conveyed effectively and reliably, paying little respect to whether the target environment is a private data center, the open cloud, or even a developer’s personal laptop. This enables designers to make unsurprising situations that are detached from the rest of the applications and can be run anyplace.

From a task point of view, aside from portability containers likewise give progressively granular authority over resources giving your foundation improved proficiency which can bring about better use of your compute resources. Want to read more about Docker Compose?

 

Running a Container

Docker run command manages running of containers. First launch the Docker container, to run a container in an interactive mode.

sudo docker run –it centos /bin/bash

you will return to your OS shell by hitting Crtl+p.

Running a Container
Running a Container

You will at that point be running in the instance of the CentOS system on the Ubuntu server.

Docker – Working with Containers

docker top

you can see the top processes within a container with this command.

Syntax:

docker top ContainerID

Options:

ContainerID − This is the ID of the Container for which you want to see the top processes.

Return Value:

Its output will show the top-level processes within a container.

Example:

sudo docker top 9f215ed0b0d3

This command will show you the top-level processes within a container.

Output:

On running the above command, it will produce the following result –

docker top output
docker top output

 

docker stop

Syntax:

docker stop ContainerID

Options:

  • ContainerID− This is the ID of the Container which needs to be stopped.

Return Value:

The output will give the ID of the container that is stopped.

Example:

sudo docker stop 9f215ed0b0d3

This command will stop the Docker container 9f215ed0b0d3.

Output:

On running the above command, it will produce the following result –

docker stop output
docker stop output

docker rm

This command is used to delete or remove a container.

Syntax:

docker rm ContainerID

Options:

  • ContainerID− This is the ID of the Container which needs to be removed.

Return Value:

The output will give you the ID of the removed container.

Example:

sudo docker rm 9f215ed0b0d3

This command will remove the Docker container 9f215ed0b0d3.

Output:

On running the above command, it will produce the following result –

docker rm output
docker rm output

 

docker stats

This command is used to provide the statistics of the container that is running.

Syntax:

docker stats ContainerID

Options:

  • ContainerID− This is the ID of the Container for which the stats need to be provided.

Return Value:

The output will show the CPU and Memory utilization of the Container as statistics.

Example:

sudo docker stats 9f215ed0b0d3

This command will provide CPU and memory utilization of the Container 9f215ed0b0d3.

Output:

On running the above command, it will produce the following result –

docker stats output
docker stats output

 

docker attach

This command is used to attach to a container that is running.

Syntax:

docker attach ContainerID

Options:

  • ContainerID− This is the ID of the Container to which you need to attach.

Return Value:

None

Example:

sudo docker attach 07b0b6f434fe

This command will attach to the Docker container 07b0b6f434fe.

Output:

On running the above command, it will produce the following result –

docker attach output
docker attach output

After attachment to the Docker container, you can run the above command to see the process utilization in that Docker container.

docker attach
docker attach

 

docker pause

This command is used to pause or stop the processes in a running container.

Syntax:

docker pause ContainerID

Options:

  • ContainerID− This is the ID of the Container to which you need to pause the processes in the container.

Return Value:

The ID of the paused container.

Example:

sudo docker pause 07b0b6f434fe

This command will pause the processes in a running container 07b0b6f434fe.

Output:

On running the above command, it will produce the following result −

docker pause output
docker pause output

 

docker unpause

This command is used to unpause or resume the processes in a running container.

Syntax:

docker unpause ContainerID

Options:

  • ContainerID− This is the ID of the Container to which you need to unpause the processes in the container.

Return Value:

The ID of the running container.

Example:

sudo docker unpause 07b0b6f434fe

This command will unpause the processes in a running container: 07b0b6f434fe

Output:

On running the above command, it will produce the following result −

docker unpause output
docker unpause output

 

docker kill

This command is used to kill or close the processes in a running container.

Syntax:

docker kill ContainerID

Options:

  • ContainerID− This is the ID of the Container to which you need to kill the processes in the container.

Return Value:

The ID of the running container.

Example:

sudo docker kill 07b0b6f434fe

This command will kill the processes in the running container 07b0b6f434fe.

Output:

On running the above command, it will produce the following result –

docker kill output
docker kill output

 

Docker – Container Lifecycle

The figure and illustrations below explain the entire lifecycle of a Docker container.

Docker Container Life Cycle
Docker Container Life Cycle
  • At the initial point, the Docker container will be in the created
  • Then the container goes into the running state when the Docker run command is used.
  • The Docker kill command is used to kill an existing container.
  • The Docker pause command is used to pause an existing container.
  • The Docker stop command is used to pause an existing container.
  • The Docker run command is used to put a Docker container back from a stopped state to a running

Prachi

NCERT-NOTES Class 6 to 12.

Related Articles

Check Also
Close
Back to top button