Docker for DevOps Engineers🐳

Docker for DevOps Engineers🐳

#Day 16 Task of #90DaysofDevops challenge🚀

Before jumping into the docker command at first you need to understand about docker

so let's start...🚗

what is Docker?😀

Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.

why docker is important for DevOps engineers?

  • Improve application portability and consistency: Docker containers are self-contained, so they can be easily moved from one environment to another without having to worry about dependencies or configuration issues. This makes it easy to deploy applications to production or to test them in different environments.

  • Speed up the development and deployment process: Docker can help to speed up the development and deployment process by providing a consistent environment for building, testing, and running applications. This can save time and reduce the risk of errors.

  • Increase reliability and scalability: Docker containers can be easily scaled up or down to meet demand, which can help improve applications' reliability and performance.

  • Reduce costs: Docker can help reduce costs by reducing the need for physical servers and making it easier to manage and maintain applications.

Now is the time to run some Docker commands

docker run: Use the docker run command to start a new container and interact with it through the command line.

ubuntu@ip-174-34-15-154:~$ docker run hello-world

output:-

Unable to find image 'hello-world: latest' locally latest: Pulling from library/hello-world 719385e32844: Pull complete Digest: sha256:c2e23624975516c7e27b1b25be3682a8c6c4c0cea011b791ce98aa423b5040a0 Status: Downloaded newer image for hello-world: latest

Hello from Docker! This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.

  2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)

  3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.

  4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.

To try something more ambitious, you can run an Ubuntu container with $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/

For more examples and ideas, visit: https://docs.docker.com/get-started/

docker inspect: Use the docker inspect command to view detailed information about a container or image. docker inspect command displays detailed information about a Docker object. This information can include the object's name, ID, status, configuration, and more.

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

For Nginx

ubuntu@ip-174-34-15-154:~$ docker port 5e5d84128d2c

output:-

80/tcp -> 0.0.0.0:80

80/tcp -> :::80

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

The docker stats command outputs a table of statistics for each container, including:

  • Name: The name of the container.

  • ID: The ID of the container.

  • CPU usage: The percentage of CPU time that the container is using.

  • Memory usage: The amount of memory that the container is using.

  • Network I/O: The amount of network traffic that the container is sending and receiving.

  • Block I/O: The amount of disk I/O that the container is performing.

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

The output of the docker top command is a table that shows the following information for each process:

  • The process ID (PID)

  • The name of the process

  • The state of the process (running, sleeping, stopped, etc.)

  • The CPU usage of the process

  • The memory usage of the process

  • The swap usage of the process

Here are some options that can be used with the docker top command:

  • -a: Show all containers, not just running ones.

  • -n: Number of processes to show.

  • -c: Show CPU usage in percentages.

  • -s: Show memory usage in kilobytes.

  • -u: Show swap usage in kilobytes.

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

The syntax for the docker save command is

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

Here are some examples of how to use the docker save command:

  • To save the image ubuntu:latest to a file called ubuntu.tar:

docker save -o ubuntu.tar ubuntu:latest

  • To save the image my-image:v1 and my-image:v2 to a single file called my-images.tar:

docker save -o my-images.tar my-image:v1 my-image:v2

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

The syntax for the docker load command is:

docker load [OPTIONS] IMAGE [IMAGE...]

Here are some examples of how to use the docker load command:

  • To load the image ubuntu:latest from a file called ubuntu.tar:

docker load -i ubuntu.tar

  • To load the image my-image:v1 and my-image:v2 from a single file called my-images.tar:

docker load -i my-images.tar

Thank you very much for giving your valuable time for reading this article !!☺😊

Arijit Manna