Day 16 of #90DaysOfDevOps Challenge

Docker

Day 16 of #90DaysOfDevOps Challenge

❄Docker:

Docker is a containerization tool that helps us create a lightweight container with all the required packages to run our application.

It has the bare minimum binaries and libraries to behave as specified OS. It uses the kernel of your host machine, unlike the virtual machines which have their kernel and OS and are very heavy.

🔹Why Docker is important:

When a developer works on some application development, he/she creates an environment for that application by installing all the prerequisites. The challenge here is if it is a VM, it is difficult to share the huge file and it takes a lot of time to boot up. If he/she only shares the application then it is hard to replicate the same environment, because the other user does not have knowledge of all the packages and required versions.

In such scenarios, containers play a very important role. A developer can spin up one container, install required dependencies, deploy the application in it, and build the image which he/she can share with the team by uploading it to the private/public repository like docker hub, they can further pull and run that image in their local machine and create a container. The same environment will be up and running within a few mins.

🔹Difference between Virtualization and containerization:


❄Tasks:

Task 1 -

Use the docker run command to start a new container and interact with it through the command line. [Hint: docker run hello-world]

Usage:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Example:

docker run -itd nginx

Options:

-i => Run with an interactive session.

-t => Allocate a pseudo-TTY.

-d => Run container in background and print container ID.

Task 2 -

Use the docker inspect command to view detailed information about a container or image.

Usage:

docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Return low-level information on Docker objects.

Below is detailed information of the docker container.

Task 3 -

Use the docker port command to list the port mappings for a container.

Usage:

docker port CONTAINER Name or ID [PRIVATE_PORT[/PROTO]]

List port mappings or specific mapping for the container.

Example:

docker run -itd --name=c1 -p 81:80 nginx

docker port c1

In the above example, I created a container and did a port mapping to 81 on the host and 80 in the container. And used the docker port command to list the port mapping.

Task 4 -

Use the docker stats command to view resource usage statistics for one or more containers.

Usage:

docker stats [OPTIONS] [CONTAINER...]

Display a live stream of container(s) resource usage statistics.

Example:

docker stats c1

Task 5 -

Use the docker top command to view the processes running inside a container.

Usage:

docker top CONTAINER [ps OPTIONS]

Display the running processes of a container

Task 6 -

Use the docker save command to save an image to a tar archive.

Usage:

docker save [OPTIONS] IMAGE [IMAGE...]

Save one or more images to a tar archive (streamed to STDOUT by default)

Example:

docker save -o nginx.tar nginx

Task 7 -

Use the docker load command to load an image from a tar archive.

Usage:

docker load [OPTIONS]

Load an image from a tar archive or STDIN

Example:

docker load -i nginx.tar

On Task 6, we created a tar file (nginx.tar) from our image (nginx) with the save command, and on this task, we created the image (nginx) using the same tar file (nginx.tar), with the load command.


Thank you for reading! 📘