Docker for DevOps Engineers

Docker for DevOps Engineers

What is Docker?

Docker is a platform that allows developers to package an application and all its dependencies into a container which can then be run on any Docker-enabled host, regardless of the underlying operating system. This makes it easy to develop, test, and deploy applications across different environments, without having to worry about compatibility issues.

Docker improves resource utilization, increases the portability and scalability of applications, and simplifies the development and deployment process.

Building a simple Flask App using Docker vs Code - Analytics Vidhya

In Docker, there are three main concepts that you need to understand: Dockerfile, Docker images, and Docker containers.

Dockerfile: A Dockerfile is a text file that contains instructions for building a Docker image.

These instructions include the base image, installing any necessary software packages and dependencies, setting environment variables, configuring the network and ports, and defining the commands to run when a container is launched.

Docker images: A Docker image is a binary file that contains everything needed to run an application. An image is built from a Dockerfile and can be stored in a registry such as Docker Hub.

Docker containers: When we run the docker image it will create a container for us that contains an application and all its dependencies. Each container is independent and can be run on any Docker-enabled host, making it easy to deploy and scale applications across different environments.

Install Docker on Ubuntu

  1. Remove any docker file running on the system using the below command,

    sudo apt-get remove docker docker-engine docker.io

  2. Update the package database,

    sudo apt-get update

  3. Install docker using the below command,

    sudo apt install docker.io

  4. Install all dependency packages,

    sudo snap install docker

  5. You can check the version of docker installed using this command,

    docker --version

  6. To check the docker installation is done correctly you can run the below command,

    sudo docker run hello-world

Tasks

As you have already installed Docker now is the time to run Docker commands.

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

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

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

    When you run the image you can use the following command it will map port 8000 of the container to port 8000 of the host machine,

    sudo docker run -d -p 8000:8000 ImageID

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

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

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

    For example, to save the httpd image to a tar archive named "httpd-image.tar".

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

    If you want to load an image from a tar archive named "httpd-image.tar".

Thank you for reading the blog.

Suggestions are always welcome. Thank you !!