<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yash Raj Singh</title>
    <description>The latest articles on DEV Community by Yash Raj Singh (@yrs147).</description>
    <link>https://dev.to/yrs147</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F991440%2F7fccd319-b552-4da9-98c5-3971bdf5e226.png</url>
      <title>DEV Community: Yash Raj Singh</title>
      <link>https://dev.to/yrs147</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yrs147"/>
    <language>en</language>
    <item>
      <title>Dock-umentary: A Beginner's Guide to Docker</title>
      <dc:creator>Yash Raj Singh</dc:creator>
      <pubDate>Tue, 03 Jan 2023 16:58:48 +0000</pubDate>
      <link>https://dev.to/yrs147/dock-umentary-a-beginners-guide-to-docker-1gao</link>
      <guid>https://dev.to/yrs147/dock-umentary-a-beginners-guide-to-docker-1gao</guid>
      <description>&lt;p&gt;Hey Everyone! , welcome to the new blog. In today's blog, we are going to learn about Docker. Having a thorough understanding of Docker can greatly benefit both developers and organizations in many ways. Hope this blog helps you jumpstart your docker journey 🐳. So let's dive into it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;In recent years, there has been a shift in the way that software is developed and deployed. In the past, many applications were built as monolithic systems, with all of the components tightly coupled and deployed together as a single unit. However, this approach has several drawbacks, including difficulty in scaling and maintaining the application, and difficulty in introducing new features or making updates.&lt;/p&gt;

&lt;p&gt;To address these issues, many organizations turned to microservice architecture, which involves breaking an application down into smaller, independent services that can be developed, deployed, and scaled independently. However, managing and deploying these microservices can be a complex and time-consuming process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2APkLr-UkFXujvt1ht.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2APkLr-UkFXujvt1ht.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, Before getting into what is docker and its other intricacies, let us first understand, why the need for docker arose. You see, prior to the release of the docker, it was often difficult for developers to ensure that their application would run consistently across different environments due to a number of reasons like differences in system configurations and dependencies between environments.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For example, if a developer developed an application on their own machine, it might rely on certain libraries or dependencies that we installed on that machine. When the developer tries to deploy the application to a different environment, such as a staging or production server, the application might not work if the required libraries or dependencies were not present. This could be due to differences in the operating system, package manager, or other system-level configurations.&lt;/p&gt;

&lt;p&gt;To address these issues, developers have to manually install and configure all the necessary dependencies and libraries on each environment where the application was deployed. This was time-consuming and print to errors, and made it difficult to ensure that the application would behave consistently across different environments.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Docker provides a solution to these challenges by allowing you to package your applications and their dependencies into lightweight, portable containers that can be easily deployed and run on any platform. With Docker, you can build, ship, and run your applications in a consistent and reliable way, regardless of the underlying infrastructure.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is docker?
&lt;/h1&gt;

&lt;p&gt;Docker is a tool that allows you to run applications in containers. These containers are isolated environments that contain all the dependencies and libraries required to run the application. This makes it easy to deploy and run applications consistently across different environments, without worrying about differences in system configurations or dependencies.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AtcRzUo-RaQ9hb7SU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AtcRzUo-RaQ9hb7SU.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting Up Docker
&lt;/h1&gt;

&lt;p&gt;To start using Docker, you will need to install it on your local development machine. Docker is available for a wide range of operating systems, including Windows, macOS, and various distros of Linux.&lt;/p&gt;

&lt;h1&gt;
  
  
  Windows
&lt;/h1&gt;

&lt;p&gt;To install Docker on Windows, you can download the Docker Desktop installer from the &lt;a href="https://docs.docker.com/desktop/install/windows-install/" rel="noopener noreferrer"&gt;Docker website&lt;/a&gt; and run it on your machine. The installer will take care of installing Docker and its dependencies, as well as setting up Docker to run as a service on your system.&lt;/p&gt;

&lt;h1&gt;
  
  
  Linux
&lt;/h1&gt;

&lt;p&gt;To install Docker on a Linux machine, you will need to follow the instructions for your specific distribution. For example, on a Debian-based system such as Ubuntu, you can use the following command to install Docker:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install docker.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  macOS
&lt;/h1&gt;

&lt;p&gt;To install Docker on macOS, you can download the Docker Desktop installer from the &lt;a href="https://docs.docker.com/desktop/install/mac-install/" rel="noopener noreferrer"&gt;Docker website&lt;/a&gt; and run it on your machine. Alternatively, you can use Homebrew to install Docker by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew cask install docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once docker is installed, you will need to create a Docker Account to log in to Docker Hub, which is a registry of Docker Images that you can use to build and run containers. To create a Docker account, visit the Docker website or click &lt;a href="https://hub.docker.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2A1dy06iSqdegsv9oo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2A1dy06iSqdegsv9oo.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After you have installed Docker and created a Docker account, you can start using Docker to build and run containers.&lt;/p&gt;

&lt;h1&gt;
  
  
  Understanding Docker Terminologies
&lt;/h1&gt;

&lt;p&gt;To work with Docker, it is important to understand the following Key concepts and terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Images&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; Docker image is a lightweight, stand-alone, executable package that contains everything needed to run an application, including the application code, libraries, dependencies, and runtime. Images are created from a set of instructions called a Dockerfile, which specifies the steps needed to build the image.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Container&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; A Docker container is a running instance of a Docker image. When you start a container, Docker creates a runtime environment that is isolated from the host system and other containers. This isolation allows you to run multiple containers concurrently on a single host without interference.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Dockerfile&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; A Dockerfile is a file that is used to automate the process of building a Docker Image, making it easier to create and deploy applications in a consistent and reproducible way.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Registry&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; A Docker registry is a collection of Docker images that can be stored and shared. Docker Hub is a public registry that stores a huge number of images that can be used by everyone.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Volume&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; A Docker volume is a persistent storage location that is used to store data that needs to be preserved between container restarts. Volumes can be used to share files between containers and host systems or to persist data that an application generates.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding these terms will be helpful as you start to work with Docker to build and run containers.&lt;/p&gt;

&lt;h1&gt;
  
  
  Using Docker Images
&lt;/h1&gt;

&lt;p&gt;One of the benefits of using Docker is its ability to easily find and use pre-built images to create and run containers. For example, if you want to try out an application without installing it in your system you can use Docker and avoid the hassle of setting up the dependencies in your local system to run the application.&lt;/p&gt;

&lt;p&gt;To display all the docker images currently installed on the system run the following command :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Al8u3s4RxUoRtjJTm" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Al8u3s4RxUoRtjJTm"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To use a prebuilt image, you can pull an image from Docker Hub.&lt;/p&gt;

&lt;h1&gt;
  
  
  Docker Hub
&lt;/h1&gt;

&lt;p&gt;Docker Hub is a public registry that hosts a large number of images that are available to everyone. These images can be used as a starting point to build and run containers for a wide range of applications and services.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Ak-X7tDI2FIvktOaK" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Ak-X7tDI2FIvktOaK"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To find and pull an image from Docker Hub, you can use the &lt;code&gt;docker pull&lt;/code&gt;command.&lt;/p&gt;

&lt;p&gt;For example, let us try to pull the latest version of the ubuntu image, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AcPJswZpAai3as_g8" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AcPJswZpAai3as_g8"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if you run the &lt;code&gt;docker images&lt;/code&gt; command you should see the ubuntu image that you just pulled from Docker Hub&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AAPfS4sl7ZAeQw-zj" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AAPfS4sl7ZAeQw-zj"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also specify a specific version of an image by including the image tag. For example, to pull the &lt;code&gt;18.04&lt;/code&gt; version of the &lt;code&gt;ubuntu&lt;/code&gt; image, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull ubuntu:18.04
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AYmxFvdg9jrrM7gnE" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AYmxFvdg9jrrM7gnE"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see now there are 2 &lt;code&gt;ubuntu&lt;/code&gt; images in the system, one with &lt;code&gt;latest&lt;/code&gt; tag and one with &lt;code&gt;18.04&lt;/code&gt; tag&lt;/p&gt;

&lt;p&gt;Once you have pulled an image from Docker Hub, you can use it to create and start a container. To create and start a container from an image, you can use the &lt;code&gt;docker run&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F688%2F0%2AgIopZCxkw2oqEjuo" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F688%2F0%2AgIopZCxkw2oqEjuo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Building Docker Images
&lt;/h1&gt;

&lt;p&gt;In addition to using pre-built images from Docker Hub, you can also create your own custom images. To create a custom image, you have to create a file with a set of instructions called a Dockerfile. A Dockerfile is a text file that contains a series of commands that are used to build an image.&lt;/p&gt;

&lt;p&gt;Let us look at an example of a Dockerfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node:latest\
RUN mkdir /app\
WORKDIR /app\
COPY package.json /app\
RUN npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Dockerfile builds an image for a Node.js application&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;FROM node:latest&lt;/code&gt;: specifies the base image as the latest version of the &lt;code&gt;node&lt;/code&gt; image&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;RUN mkdir /app&lt;/code&gt;: creates a new directory called &lt;code&gt;/app&lt;/code&gt; in the image&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;WORKDIR /app&lt;/code&gt;: sets the working directory to &lt;code&gt;/app&lt;/code&gt; for subsequent instructions in the Dockerfile&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;COPY package.json /app&lt;/code&gt;: copies the &lt;code&gt;package.json&lt;/code&gt; file from the host into the &lt;code&gt;/app&lt;/code&gt; directory in the image&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;RUN npm install&lt;/code&gt;: installs the dependencies listed in the &lt;code&gt;package.json&lt;/code&gt; file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After this save the file with the name Dockerfile&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;(Note --- 'D' in the Dockerfile should be in uppercase)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now use the &lt;code&gt;docker build&lt;/code&gt; command to build the image :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build [OPTIONS] PATH | URL | -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Pushing Docker Images
&lt;/h1&gt;

&lt;p&gt;Once you have created a docker image you can also push this image to the docker registry (Docker Hub). There are many benefits to it :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  It allows you to share your images with other people.&lt;/li&gt;
&lt;li&gt;  It allows you to version your images, so you can roll back to previous versions if needed.&lt;/li&gt;
&lt;li&gt;  Having your images stored on Docker Hub makes it easier to automate the deployment of your applications (Eg- While building a CICD pipeline)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can push the docker image using the &lt;code&gt;docker push&lt;/code&gt; command :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker push [OPTIONS] NAME[:TAG]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note that before you can use the docker push command, you need to be logged in to the Docker registry where you want to push the image. Use the docker login command to do so .&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Docker Image commands
&lt;/h1&gt;

&lt;p&gt;Here is a list of some common Docker image commands that you can use :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;docker image ls&lt;/code&gt;: lists all images&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker image pull &amp;lt;IMAGE_NAME&amp;gt;&lt;/code&gt;: pulls an image from a registry&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker image build -t &amp;lt;IMAGE_NAME&amp;gt; .&lt;/code&gt;: builds an image from a Dockerfile in the current directory&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker image inspect &amp;lt;IMAGE_NAME&amp;gt;&lt;/code&gt;: displays detailed information about an image&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker image tag &amp;lt;IMAGE_NAME&amp;gt; &amp;lt;NEW_TAG&amp;gt;&lt;/code&gt;: tags an image with a new name&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker image push &amp;lt;IMAGE_NAME&amp;gt;&lt;/code&gt;: pushes an image to a registry&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker image rm &amp;lt;IMAGE_NAME&amp;gt;&lt;/code&gt;: removes an image&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker image prune&lt;/code&gt;: removes all unused images&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Managing Docker containers
&lt;/h1&gt;

&lt;p&gt;After successfully building or pulling the image you can start off a container using the following command :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker container run [OPTIONS] IMAGE [COMMAND] [ARG...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have started a Docker container, you will need to be able to manage it. This includes tasks such as starting and stopping the container, viewing and managing the container logs, and removing the container when it is no longer needed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Aor9DtVxWTR9mbbPA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Aor9DtVxWTR9mbbPA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Docker Container commands
&lt;/h1&gt;

&lt;p&gt;Here is a list of some common docker container commands you can use :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;docker container ls&lt;/code&gt;: lists all running containers&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker container ls -a&lt;/code&gt;: lists all containers, including stopped ones&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker container start &amp;lt;CONTAINER_ID&amp;gt;&lt;/code&gt;: starts a stopped container&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker container stop &amp;lt;CONTAINER_ID&amp;gt;&lt;/code&gt;: stops a running container&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker container rm &amp;lt;CONTAINER_ID&amp;gt;&lt;/code&gt;: removes a container&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker container kill &amp;lt;CONTAINER_ID&amp;gt;&lt;/code&gt;: sends a SIGKILL signal to a running container&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker container inspect &amp;lt;CONTAINER_ID&amp;gt;&lt;/code&gt;: displays detailed information about a container&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker container logs &amp;lt;CONTAINER_ID&amp;gt;&lt;/code&gt;: displays the logs for a container&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker container stats &amp;lt;CONTAINER_ID&amp;gt;&lt;/code&gt;: displays resource usage statistics for a running container&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Docker Storage
&lt;/h1&gt;

&lt;p&gt;Docker uses a union file system to manage the file system of a container. This allows multiple layers of files to be stacked on top of each other, with the topmost layer taking precedence.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F345%2F0%2AWc2pUYA9RL1IYkOM" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F345%2F0%2AWc2pUYA9RL1IYkOM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But the question still remains how does Docker store files of an image and a container?&lt;/p&gt;

&lt;p&gt;To understand this better you first need to learn about the layered architecture in docker.&lt;/p&gt;

&lt;h1&gt;
  
  
  Layered Architecture of Docker Images
&lt;/h1&gt;

&lt;p&gt;Docker uses a layered architecture for its images, which allows for efficient image management and distribution. A Docker image is made up of layers, each of which represents a different step in the build process for the image. When you create an image, each step in the build process is recorded as a new layer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2A5a5wpZISL0WPylpi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2A5a5wpZISL0WPylpi.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Image Layers&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;All of the image layers are created when we run the &lt;code&gt;docker build&lt;/code&gt; command to form the final Docker image. And once the image is built you cannot modify the contents of this layer so that's why they are Read Only and can only be modified by starting a new build&lt;/p&gt;

&lt;p&gt;Remember --- The same image layer is shared by all the containers created using this image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Container Layer&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you run a container of this image, docker creates a container based on these layers and creates a new writable layer on top of the image layers. The writeable layer is used to store data created by the container like log files written by the application, any temporary files created, etc.&lt;/p&gt;

&lt;p&gt;This layer is alive only till the container is up and running. When the container is destroyed, this layer and all of the changes stored in this layer are also destroyed.&lt;/p&gt;

&lt;p&gt;You can refer to the example below for better clarity.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2A5_bGhhGh7RZinwua.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2A5_bGhhGh7RZinwua.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This Dockerfile creates an image with four layers: the base image, the layer containing the files from the current directory, the layer containing the results of the &lt;code&gt;make&lt;/code&gt; command, and the layer specifying the default command to run. When you build an image using this Dockerfile, the layers will be stored in a cache on your local machine, and you can use the image to create and run containers.&lt;/p&gt;

&lt;h1&gt;
  
  
  Docker Volumes
&lt;/h1&gt;

&lt;p&gt;Docker volumes are persistent storage locations that are used to store container data that needs to be preserved. Volumes can be used to share files between containers and host systems or to persist data that an application generates.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F334%2F0%2AuAbW-NRUjxrOIMrD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F334%2F0%2AuAbW-NRUjxrOIMrD.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a named volume, you can use the &lt;code&gt;docker volume create&lt;/code&gt; command. For example, to create a volume named &lt;code&gt;myvolume&lt;/code&gt;, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker volume create myvolume
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To mount a volume to a container, you can use the &lt;code&gt;-v&lt;/code&gt; flag with the &lt;code&gt;docker run&lt;/code&gt; command. For example, to mount the &lt;code&gt;myvolume&lt;/code&gt; volume to the &lt;code&gt;/app/data&lt;/code&gt; directory inside a container, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -it -v myvolume:/app/data ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use the &lt;code&gt;-v&lt;/code&gt; flag to mount a host directory to a container. For example, to mount the &lt;code&gt;/data&lt;/code&gt; directory on the host system to the &lt;code&gt;/app/data&lt;/code&gt; directory inside a container, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -it -v /data:/app/data ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a list of some common Docker volume commands you can use :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;docker volume ls&lt;/code&gt;: lists all volumes&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker volume create &amp;lt;VOLUME_NAME&amp;gt;&lt;/code&gt;: creates a new volume&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker volume inspect &amp;lt;VOLUME_NAME&amp;gt;&lt;/code&gt;: displays detailed information about a volume&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker volume rm &amp;lt;VOLUME_NAME&amp;gt;&lt;/code&gt;: removes a volume&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker volume prune&lt;/code&gt;: removes all unused volumes&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Networking in Docker
&lt;/h1&gt;

&lt;p&gt;Docker creates 3 networks automatically when it is installed &lt;code&gt;bridge&lt;/code&gt;, &lt;code&gt;none&lt;/code&gt;, and &lt;code&gt;host&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AxmDCqBsaItJW2vUJ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AxmDCqBsaItJW2vUJ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Bridge
&lt;/h1&gt;

&lt;p&gt;This is the default network type when you run a container. It creates a private network inside the Docker daemon and assigns a virtual IP address to the container. This network allows the container to communicate with other containers on the same network and with the host, but it is isolated from the outside world.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AdZzJ5zb3YVVhFyHH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AdZzJ5zb3YVVhFyHH.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  None
&lt;/h1&gt;

&lt;p&gt;This network type removes all networking from the container. The container will not be able to communicate with the host or any other containers. This is useful if you want to run a process in a container without any networking in complete isolation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run &amp;lt;image&amp;gt; --network=none
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F606%2F0%2A9OqLXtMGzeWtFVhb" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F606%2F0%2A9OqLXtMGzeWtFVhb"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Hosts
&lt;/h1&gt;

&lt;p&gt;This network type removes networking isolation between the container and the host. The container will use the host's network stack and will be able to access the host's network resources directly. This is useful if you want to run a container that needs to listen on a specific port on the host.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run &amp;lt;image&amp;gt; --network=host
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F607%2F0%2ADJN2rwJRCV0qkYuy" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F607%2F0%2ADJN2rwJRCV0qkYuy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  User Defined Networks
&lt;/h1&gt;

&lt;p&gt;By default, containers are connected to the same network, when multiple containers are created on the same Docker host, they are all connected via a single bridge with an IP address such as 172.17.0.1. If you want to create a new bridge with a different IP address (e.g., 182.18.0.1) on the same host, you can do so using the appropriate command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker network create \
    --driver bridge \
    --subnet 182.18.0.0/16 
    user-def
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Aocnu3IFfw-_abzZC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Aocnu3IFfw-_abzZC.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Docker Networking commands
&lt;/h1&gt;

&lt;p&gt;Here is a list of some common Docker networking commands you can use :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;docker network ls&lt;/code&gt;: lists all networks&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker network create &amp;lt;NETWORK_NAME&amp;gt;&lt;/code&gt;: creates a new network&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker network inspect &amp;lt;NETWORK_NAME&amp;gt;&lt;/code&gt;: displays detailed information about a network&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker network connect &amp;lt;NETWORK_NAME&amp;gt; &amp;lt;CONTAINER_ID&amp;gt;&lt;/code&gt;: connects a container to a network&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker network disconnect &amp;lt;NETWORK_NAME&amp;gt; &amp;lt;CONTAINER_ID&amp;gt;&lt;/code&gt;: disconnects a container from a network&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;docker network rm &amp;lt;NETWORK_NAME&amp;gt;&lt;/code&gt;: removes a network&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Docker Compose
&lt;/h1&gt;

&lt;p&gt;Docker Compose is a tool that helps you manage and deploy multi-container applications. It allows you to define all the services that make up your application in a single file called a &lt;code&gt;docker-compose.yml&lt;/code&gt; file. You can then use a single command to create and start all the services defined in the file.&lt;/p&gt;

&lt;p&gt;To use Docker Compose, you will first need to install it on your system. You can find instructions for installing Docker Compose on the Docker Compose &lt;a href="https://docs.docker.com/compose/install/linux/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; page.&lt;/p&gt;

&lt;p&gt;Once Docker Compose is installed, you can create a &lt;code&gt;docker-compose.yml&lt;/code&gt; file in the directory where you want to run your application. This file should contain the definitions for the services that make up your application.&lt;/p&gt;

&lt;p&gt;Let's look at an example &lt;code&gt;docker-compose.yml&lt;/code&gt; file for a simple web application :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3'
services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
  db:
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  The &lt;code&gt;version&lt;/code&gt; field specifies the version of the Docker Compose file format. In this case, it is using version 3.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;services&lt;/code&gt; block defines the services that make up the application. In this example, there are two services: &lt;code&gt;web&lt;/code&gt; and &lt;code&gt;db&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;web&lt;/code&gt; service is based on the &lt;code&gt;nginx:latest&lt;/code&gt; Docker image. This image will be pulled from a Docker registry, such as Docker Hub, if it is not already present on the host machine.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;ports&lt;/code&gt; field specifies that the &lt;code&gt;web&lt;/code&gt; service should expose port 80 on the host machine and map it to port 80 inside the container.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;db&lt;/code&gt; service is based on the &lt;code&gt;mysql:latest&lt;/code&gt; Docker image.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;environment&lt;/code&gt; field specifies environment variables that should be passed to the &lt;code&gt;db&lt;/code&gt; container. In this case, it sets the &lt;code&gt;MYSQL_ROOT_PASSWORD&lt;/code&gt; environment variable to &lt;code&gt;password&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Docker Architecture
&lt;/h1&gt;

&lt;p&gt;The Docker architecture consists of three main components: the Docker host, the Docker client, and the Docker registry.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F609%2F0%2AR5uq8rG71dCjMWsI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F609%2F0%2AR5uq8rG71dCjMWsI.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Docker Host
&lt;/h1&gt;

&lt;p&gt;The Docker host is the machine on which the Docker daemon runs. The Docker daemon is responsible for running containers and managing their resources, such as CPU, memory, and storage. The Docker host can be a physical machine or a virtual machine, and it can run on a variety of operating systems, including Linux, macOS, and Windows.&lt;/p&gt;

&lt;h1&gt;
  
  
  Docker Client
&lt;/h1&gt;

&lt;p&gt;The Docker client is the interface used to send commands to the Docker daemon. The client can be installed on the same machine as the daemon, or it can be installed on a separate machine and used to communicate with the daemon over a network. The Docker client and daemon communicate with each other using a REST API.&lt;/p&gt;

&lt;h1&gt;
  
  
  Docker Registry
&lt;/h1&gt;

&lt;p&gt;The Docker registry is a storage and distribution system for Docker images. It allows users to upload and download images, and it acts as a central repository for sharing images with others. The Docker registry can be a public registry, such as Docker Hub, or it can be a private registry run by an organization.&lt;/p&gt;

&lt;h1&gt;
  
  
  Container Orchestration
&lt;/h1&gt;

&lt;p&gt;Container orchestration refers to the process of managing and deploying multiple containers as a single, cohesive application. This involves automating the deployment, scaling, and management of containers across a cluster of machines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Ad8wQt8wccMq8Ww9N.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2Ad8wQt8wccMq8Ww9N.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are several tools and platforms available for container orchestration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Docker Swarm&lt;/li&gt;
&lt;li&gt;  Kubernetes&lt;/li&gt;
&lt;li&gt;  RedHat Openshift&lt;/li&gt;
&lt;li&gt;  Mesos&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since container orchestration in itself is a big topic, so we'll deep dive into the world of orchestration some other day. Until then," happy building and deploying with Docker! 😄"&lt;/p&gt;

&lt;p&gt;You can catch me up on my Socials for more such content : &lt;a href="https://bio.link/yashrajsingh" rel="noopener noreferrer"&gt;Link&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  References 📚
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://docs.docker.com/" rel="noopener noreferrer"&gt;Docker Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.youtube.com/watch?v=fqMOX6JJhGo" rel="noopener noreferrer"&gt;Docker Tutorial for Beginners&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://cognitiveclass.ai/courses/docker-essentials" rel="noopener noreferrer"&gt;Docker Essentials: A Developer Introduction&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>docker</category>
      <category>beginners</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
