Docker for DevOps Engineers

Docker for DevOps Engineers

📍Introduction

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. With Docker, we can able to run each component in a separate container with its dependencies and its libraries all on the same VM and the OS within a separate environment.

🔹What is Container?

Containers are completely isolated environments. As they have their separate processes, services, network interface, their mounts, expect they all share the same OS kernel. we can package our application with all its dependencies and libraries in a container so that I can run it in any environment. Technically they are just a runtime instance of the docker image

What is a Docker Container?

🔹Why do we need Docker?

Suppose we need requirements to set up an end-to-end application including different technologies like a web server using node js and a database such as mongo dB and messaging system or an orchestration tool like ansible. We have all these issues for developing this application with all these components.

  1. We have to ensure that all these components are compatible with the OS.

  2. Suppose one service required one version and another service required another version.

  3. We have to upgrade to new versions of these components or change the database.

  4. One developer may be comfortable with one OS and another may be another OS.

  5. We couldn’t guarantee that the application that we were building would run the same way in different environments.

🔹What is a Docker image?

Docker images are the executable packages bundled with the application code and dependencies software packages, etc. to create containers. Docker images can be deployed to any docker environment and the containers can be spun up there to run the application.

Following are the essential commands in docker.

🔹Docker Commands

  1. docker run <options> <image> <command> <arg>: The docker run command is used to create and start a container based on a Docker image.

    Here are some commonly used options:

    -d - Run the container in detached mode.

    -p - publish container port to the host.

    -v - Bind mount a volume

    --name - Assign a name to the container

    --rm - automatically remove the container when it exits

    -it - To run the command in an interactive terminal

  2. docker inspect<container/image>: This command to view detailed information about a container or image.

  3. docker port <container>: The docker port command to list the port mapping for a container.

  4. docker stats <container>: The docker stats command to view the processes running inside the container.

  5. docker top <container>: The docker top command to view resource usage for one or more containers.

  6. docker save -o <file path> <image> : The docker saves command to save an image to a tar archive.

  7. docker load -i <file path>: The docker load command to load an image from a tar archive.

  8. docker images: The docker images command lists all the images that exist.

  9. docker ps: The docker ps command lists all the running containers.

  10. docker ps -a: The docker ps -a command lists all the stopped and running containers.

For more useful commands I have added a cheatsheet for your reference.

📍Conclusion

Docker provides an efficient and effective way to package and deploy applications by using containers. With the ability to create isolated environments, Docker allows for faster and more consistent deployment of applications, regardless of the underlying infrastructure. The essential Docker commands provided in this blog, include all the commands required to utilize, manage and monitor containers and images. By using Docker and its powerful commands, developers can streamline their application deployment processes and reduce the likelihood of errors and inconsistencies.

Did you find this article valuable?

Support Ashutosh Mahajan's blog by becoming a sponsor. Any amount is appreciated!