Debug School

Day 1 Assignment

What is Docker?

Docker is a container management tool. The unit of execution in this tool is called container.

Why We need docker?

Inorder to ease the tight coupling with host OS and the kernel and also effective utilisation of resources like CPU and memory.

What is Container?

Container is a light weight runtime environment which uses less CPU,RAM and less storage. Each container has its own network,Mount, PID tree.

How Container Works?

Docker has a container runtime (like containerd) running, which interacts with kernel.
Docker container runs as per instructions in the docker image. Each container has its own user, resources(kernel namespace, cgroups). containerd requests kernel for resources for the specific user and tags them to that. Similar way other container will have its own resources. So we can have multiple users running parallly without any interaction with each other.

How to install Docker?

Docker installation steps varies from the OS to OS. Based on the host OS, we can select the appropriate package installers like apt,yum,rpm based or we also have scripts available for the same in open source.

What are the components docker?

Docker is a client server architecture.

  1. Docker client/Docker Engine: This takes care of sending/routing the docker instructions we give, to the docker server running in our system.
  2. Docker server/ Docker D: docker daemon once receives the instruction sends it to the container and contiainer sends it to the kernel and this is how the process goes on.
  3. Docker Images: Docker Image is the heart of the container. The executable format of a Dockerfile is docker image. Dockerfile consists of all the instructions on how the process inside the container should behave.
  4. Docker Registry: This is like a store/repo for docker images. We can pull/push from the registry. Always when running a container it first checks if the image is present in local, if not it pulls from the registry. The registry details can be found from the command "docker info"
  5. Docker container

What is a container lifecycle commands?

  1. docker create - create a container
  2. docker start container_id - start the container
  3. docker pause container_id - pause a running container
  4. docker unpause container_id- unpause paused container
  5. docker stop container_id- stop running container
  6. docker remove or docker rm container_id - remove stopped container
  7. Container can only be removed if it is not running.
  8. Special case is killing container without stopping it. container gets killed if there is any issue with the process running in it. command: docker kill container_id

What is docker pause/unpuase?

docker pause container_id - Pauses the container. This means there will not be any cpu allocated for this container. But we can see memory attached to it eventhough paused
docker unpause container_id - unpause the paused container so that cpu gets allocated and we can access the container.
cpu is allocated only when we access the container.
docker stats - command gives the details of resource utilisation

What is docker stop/kill?

docker stop - runs a graceful container stop where the exit code will be 0. This means that the process running inside container has been completed succesfully.
docker kill container_id - This is a forceful container stop and the exit code will be anything other than 0. Like 137,2 etc.. This can be due to abrupt shutdown of the process running or manual kill by the user.

How to get inside a container?

exec commands are used to get inside container
docker exec -it container_id /bin/bash
Here the shell can vary upon the user's requirement. In this command we are executing and interactive terminal to the container as a bash shell.

How to access container from outside?

This can be done through the network.
**Docker inspect container_id **gives the ip details of the container and we can curl or ping to the ip to know the status of the process (http or nginx). Other way is to port forward it to local and access it from host machines network itself.

What is the rule for container is running?

For a container to be in running state, the Process ID 1 (PID 1) should be always running. This can be any process unlike VM and PC where the PID 1 is a system process.

Top comments (0)