Docker for DevOps Engineers (Part 1)

Docker for DevOps Engineers (Part 1)

  1. What is Docker?

  • Docker is an open-source platform designed to automate the deployment, scaling, and management of applications.

  • It uses containerization technology to package applications and their dependencies into containers, which can run on any system with Docker installed.

  • This ensures that the software will always run the same, regardless of its environment.


  1. Why Docker Was Invented?

  • Environment Consistency: Docker ensures that applications run the same regardless of where they are deployed.

  • Dependency Management: Docker packages all dependencies with the application, ensuring compatibility.

  • Efficient Resource Usage: Traditional virtual machines are resource-intensive. Docker provides a lightweight alternative by sharing the host OS, leading to better resource utilization.

  • Fast and Reliable Deployment: Docker enables rapid deployment of applications by packaging them into containers. This speeds up the deployment process and reduces errors.

  • Isolation: Containers provide isolated environments for applications, improving security and reducing conflicts between different applications.

  • Scalability: Docker makes it easy to scale applications horizontally by adding more containers.


  1. Features of Docker

  • Lightweight: Containers share the host OS kernel and are more lightweight than virtual machines.

  • Portability: Containers can run on any system that supports Docker, making it easy to move applications between environments.

  • Isolation: Each container runs in its own isolated environment, ensuring that applications do not interfere with each other.

  • Scalability: Docker makes it easy to scale applications up or down quickly.

  • Version Control: Docker images can be versioned, allowing for easy rollback to previous versions.

  • Security: Containers provide a level of security by isolating applications from the host system and each other.

  • Resource Efficiency: Containers use fewer resources than traditional VMs since they share the host OS.


  1. Usage of Docker

  • Development: Developers use Docker to create consistent development environments that match production.

  • CI/CD: Docker integrates with continuous integration and continuous deployment (CI/CD) tools, facilitating automated testing and deployment.

  • Microservices: Docker is commonly used to deploy microservices architectures, where each service runs in its own container.

  • Testing: Containers can be used to create isolated test environments, making it easy to test applications in different scenarios.

  • Deployment: Docker simplifies the deployment process by packaging applications and their dependencies together.

  • Hybrid and Multi-cloud: Docker makes it easy to run applications across different cloud providers and on-premises environments.


  1. Task : Run simple Docker commands

Install Docker in Linux

Installing in Debian distribution,

linux$ sudo apt update # Update repository of packages to latest
linux$ sudo apt install docker.io -y # Install Docker

Check version of Docker,

linux$ docker --version
Docker version 18.09.1, build 4c52b90

After installing docker you will get error like, error is due to your logged in user don't have permission to run docker command.

linux$ docker images
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/images/json: dial unix /var/run/docker.sock: connect: permission denied

Solution for this is, add currently logged user into docker group.

linux$ sudo usermod -aG docker $USER

If still error is visible then restart your system to resolve the issue.


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

linux$ docker run hello-world

'docker run' is used to start a new container and interact with it through the command line.

There is no images present.

linux$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:1408fec50309afee38f3535383f5b09419e6dc0925bc69891e79d84cc4cdcec6
Status: Downloaded newer image for hello-world:latest
linux$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              d2c94e258dcb        14 months ago       13.3kB
linux$ docker pull hello-world # Pulling hello-world image from docker registry


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

To view detailed information about a container or an image, Use 'docker inspect' command.

 # Inspect a container
linux$ docker inspect <container_id_or_name>

# Inspect an image
linux$ docker inspect <image_id_or_name>


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

To list the port mappings for a container, use the 'docker port' command.

linux$ docker port <container_id_or_name>

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

linux$ docker port <container_id_or_name>


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

linux$ docker top <container_id_or_name>

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

linux$ docker save -o <path_to_output_tar> <image_id_or_name>


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

linux$ docker load -i nginx_image.tar


Connect Me

LinkedIn | GitHub

Follow me for more amazing content :)