<?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: Reesav Gupta</title>
    <description>The latest articles on DEV Community by Reesav Gupta (@reesavgupta).</description>
    <link>https://dev.to/reesavgupta</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%2F1932639%2F5566da43-50a8-4c36-b3b6-5b7278b25202.jpeg</url>
      <title>DEV Community: Reesav Gupta</title>
      <link>https://dev.to/reesavgupta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/reesavgupta"/>
    <language>en</language>
    <item>
      <title>Mastering Docker: A Beginner's Guide to Containerization</title>
      <dc:creator>Reesav Gupta</dc:creator>
      <pubDate>Sun, 18 Aug 2024 19:51:50 +0000</pubDate>
      <link>https://dev.to/reesavgupta/mastering-docker-a-beginners-guide-to-containerization-2ae1</link>
      <guid>https://dev.to/reesavgupta/mastering-docker-a-beginners-guide-to-containerization-2ae1</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;&lt;strong&gt;Why Containerisation?&lt;/strong&gt;&lt;/em&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Everyone has a different operating system&lt;/li&gt;
&lt;li&gt;steps to run a project can vary based on the operating system&lt;/li&gt;
&lt;li&gt;Extremely harder to keep track of dependencies as a project grows&lt;/li&gt;
&lt;li&gt;What if there was a way to describe your project's configuration in a single file&lt;/li&gt;
&lt;li&gt;What if that could be run in an isolated environment&lt;/li&gt;
&lt;li&gt;Makes local setup of OS projects a breeze&lt;/li&gt;
&lt;li&gt;Makes installing auxiliary services very simple&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Definition&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Containerization involves building self-sufficient software packages that perform consistently, regardless of the machines they run on.&lt;br&gt;
It's taking the snapshot of a machine, the filesystem, and letting you use and deploy it as a construct.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;note:- Allows for container orchestration which makes deployment a breeze.&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Docker has 3 parts
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CLI&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The CLI is where Docker commands are executed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Engine&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker Engine is the heart of Docker and is responsible for running and managing containers. It includes:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Docker Daemon:&lt;/strong&gt; Runs on the host, managing images, containers, networks, and storage.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Registry&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker Registry is a system for storing and sharing Docker images. It can be public or private, allowing users to upload and download images for easy collaboration and deployment.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Docker Hub:&lt;/strong&gt; The default public registry with millions of images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Private Registries:&lt;/strong&gt; Custom, secure repositories organizations use to control their images.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;
  
  
  Images v/s Containers
&lt;/h2&gt;

&lt;p&gt;A docker image behaves like a template from which consistent containers can be created.&lt;/p&gt;

&lt;p&gt;if docker was a traditional virtual machine, the image could be likened to the ISO used to install your VM. This isn't a robust comparison, as Docker differs from VMs in concept and implementation, but it's a useful starting point nonetheless.&lt;/p&gt;

&lt;p&gt;Images define the initial filesystem state of new containers. They bundle your application's source code and its dependencies into a self-contained package runtime. Within the image, filesystem content is represented as multiple independent layers.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Containerize an App
&lt;/h2&gt;

&lt;p&gt;Below is an example of a simple Dockerfile for a Node.js backend application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# Use Node.js version 20 as the base image&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; node:20&lt;/span&gt;

&lt;span class="c"&gt;# Set up a working directory inside the container&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /usr/src/app&lt;/span&gt;

&lt;span class="c"&gt;# Copy the contents of the current directory to the working directory in the container&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="c"&gt;# Install dependencies specified in package.json&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="c"&gt;# Expose the container's port 3000 to the host machine&lt;/span&gt;
&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 3000&lt;/span&gt;

&lt;span class="c"&gt;# Define the command to run the application when the container starts&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["node", "index.js"]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the first four lines of code i.e., &lt;br&gt;
&lt;code&gt;FROM node:20&lt;br&gt;
 WORKDIR /usr/src/app &lt;br&gt;
 COPY . . &lt;br&gt;
 RUN npm install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;these run while the image is being created but the line &lt;/p&gt;

&lt;p&gt;&lt;code&gt;CMD ["node", "index.js"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;executes only while the container starts. The expose 3000 is only exposing a port so we won't be considering that.&lt;/p&gt;
&lt;h3&gt;
  
  
  Build and Run the Docker Image
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Build the Docker image&lt;/span&gt;
docker build &lt;span class="nt"&gt;-t&lt;/span&gt; my-node-app &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;#Run the Docker container&lt;/span&gt;
docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 3000:3000 my-node-app

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;docker build -t my-node-app .&lt;/code&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;here the -t flag signifies the tag-name&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;docker run -p 3000:3000 my-node-app&lt;/code&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;all the requests coming to my machine at port 3000 should be routed to port 3000 of the container&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Caching and Layers
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt; FROM node:20                &lt;span class="c"&gt;#layer1&lt;/span&gt;
 WORKDIR /usr/src/app        &lt;span class="c"&gt;#layer2&lt;/span&gt;
 COPY . .                    #layer3
 RUN npm install             &lt;span class="c"&gt;#layer4&lt;/span&gt;
 EXPOSE 3000
 CMD ["node", "index.js"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;When building Docker images, each command in the Dockerfile creates a new layer. Docker caches these layers to speed up future builds. However, if one layer changes, all layers after it must be rebuilt.&lt;/p&gt;

&lt;p&gt;Why layers?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;caching&lt;/li&gt;
&lt;li&gt;Re-using layers&lt;/li&gt;
&lt;li&gt;Faster build time&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Problem: Layer Dependency in Docker Images&lt;br&gt;
Layer 3: The COPY . . command copies your entire project into the container, depending on your project files.&lt;br&gt;
Issue: If you update any files (like index.js), Docker detects this change and rebuilds Layer 3 and all layers after it, such as RUN npm install. This can slow down the build, especially if later steps are time-consuming.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# Solution to the above-mentioned problem statement&lt;/span&gt;

 FROM node:20                &lt;span class="c"&gt;#layer1&lt;/span&gt;
 WORKDIR /usr/src/app        &lt;span class="c"&gt;#layer2&lt;/span&gt;
 COPY package *.             #layer3
 RUN npm install             &lt;span class="c"&gt;#layer5&lt;/span&gt;
 COPY . .                    #layer4
 EXPOSE 3000
 CMD ["node", "index.js"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How Reordering Solves the Problem
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Layer 1: &lt;code&gt;FROM node:20&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Base Image:&lt;/strong&gt; Sets up the environment. Rarely changes, so it’s cached.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Layer 2: &lt;code&gt;WORKDIR /usr/src/app&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Working Directory:&lt;/strong&gt; Stable and rarely changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Layer 3: &lt;code&gt;COPY package*.json ./&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Copy Dependencies:&lt;/strong&gt; Copies &lt;code&gt;package.json&lt;/code&gt;. Rebuilt only if dependencies change.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Layer 4: &lt;code&gt;RUN npm install&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Install Dependencies:&lt;/strong&gt; Installs Node.js packages. Cached unless dependencies change.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Layer 5: &lt;code&gt;COPY . .&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Copy Project Files:&lt;/strong&gt; Copies the rest of the project. Rebuilt only if files change.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Benefits:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Faster Rebuilds:&lt;/strong&gt; Only the final layer (&lt;code&gt;COPY . .&lt;/code&gt;) rebuilds on code changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Isolation:&lt;/strong&gt; Keeps &lt;code&gt;npm install&lt;/code&gt; cached unless &lt;code&gt;package.json&lt;/code&gt; changes.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Volumes &amp;amp; Networks
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Docker is used to run DBs/Redis/Auxiliary services locally.&lt;/li&gt;
&lt;li&gt;This is useful when we don't want to pollute our filesystem with unnecessary dependencies.&lt;/li&gt;
&lt;li&gt;We can bring up or bring down those services to clean our machine.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;There is a problem&lt;br&gt;
-We want the local databases to retain information across restarts(can be achieved using volumes.).&lt;br&gt;
-We want to allow one docker container to talk to another docker container(can be achieved using networks.).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;we shall discuss this further:-&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Volumes&lt;/em&gt;&lt;/strong&gt; :
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Used for persisting data across starts.&lt;/li&gt;
&lt;li&gt;Specifically useful for things like a database.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume create volume_db

docker run &lt;span class="nt"&gt;-v&lt;/span&gt; volume_db:/data/db &lt;span class="nt"&gt;-p&lt;/span&gt; 27017:27017 mongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;docker run -v volume_name:/data/db -p 27017:27017 mongo&lt;/p&gt;

&lt;p&gt;-&lt;em&gt;Purpose&lt;/em&gt;: Runs a MongoDB container.&lt;/p&gt;

&lt;p&gt;-&lt;em&gt;Volume&lt;/em&gt;: Mounts the volume_name volume to store MongoDB data at /data/db inside the container.&lt;/p&gt;

&lt;p&gt;-&lt;em&gt;Port&lt;/em&gt;: Maps port 27017 on the host to port 27017 in the container, allowing access to MongoDB from the host machine.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Networks&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Falen8zgx1pc0o8tz3zrt.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Falen8zgx1pc0o8tz3zrt.PNG" alt="Backend service need to be connected in the same  network as mongo service or vice-versa to perform communication." width="638" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Each container has its own local host. So we'll need to form a network for the containers to communicate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Containers have their own network&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;One container can't talk to the host machine or other containers&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network create my-custom-network

docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 3000:3000 &lt;span class="nt"&gt;--name&lt;/span&gt; backend &lt;span class="nt"&gt;--network&lt;/span&gt; my-custom-network &amp;lt;image_tag&amp;gt;

docker run &lt;span class="nt"&gt;-v&lt;/span&gt; volume_name:/data/db &lt;span class="nt"&gt;--name&lt;/span&gt; mongo &lt;span class="nt"&gt;--network&lt;/span&gt; my-custom-network &lt;span class="nt"&gt;-p&lt;/span&gt; 27017:27017 mongo

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Multi-Stage Builds
&lt;/h2&gt;

&lt;p&gt;What if we want to allow the development backend to hot reload? &lt;br&gt;
But the production environment to not?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hot Reloading: Ensure your npm run dev script in package.json uses a tool like nodemon for hot reloading.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;node:20&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;Base&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /usr/src/app&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;Base&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;development&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["npm", "run", "dev"]&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;Base&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;production&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;npm prune &lt;span class="nt"&gt;--production&lt;/span&gt; 
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["npm", "run", "start"]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;while building dev:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;--target&lt;/span&gt; development &lt;span class="nt"&gt;-t&lt;/span&gt; tag-name:dev
docker run &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;MONGO_URI&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mongodb://127.0.0.1:27017/my_db &lt;span class="nt"&gt;-p&lt;/span&gt; 3000:3000 &lt;span class="nt"&gt;-v&lt;/span&gt; .:/usr/src/app myapp:dev

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;while building prod&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;--target&lt;/span&gt; production &lt;span class="nt"&gt;-t&lt;/span&gt; tag-name:dev
docker run &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;MONGO_URI&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mongodb://127.0.0.1:27017/my_db &lt;span class="nt"&gt;-p&lt;/span&gt; 3000:3000 &lt;span class="nt"&gt;-v&lt;/span&gt; .:/usr/src/app myapp:dev

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Docker Compose &amp;amp; YAML Files
&lt;/h2&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Docker Compose&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Docker Compose is a tool for defining and running multi-container Docker applications. With Docker Compose, you can use a YAML file to configure your application’s services, networks, and volumes. Then, with a single command, you can create and start all the services from your configuration.&lt;/p&gt;

&lt;p&gt;key commands:-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start services: docker compose up&lt;/li&gt;
&lt;li&gt;Stop and remove services: docker compose down&lt;/li&gt;
&lt;li&gt;View logs: docker compose logs&lt;/li&gt;
&lt;li&gt;List services: docker compose ps&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example for a docker-compose.yml file:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3'&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;web&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3000:3000"&lt;/span&gt;
    &lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;frontend&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;backend&lt;/span&gt;
    &lt;span class="na"&gt;depends_on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;db&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;DB_HOST&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;db&lt;/span&gt;
      &lt;span class="na"&gt;DB_PORT&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5432&lt;/span&gt;
      &lt;span class="na"&gt;REDIS_HOST&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;redis&lt;/span&gt;
      &lt;span class="na"&gt;REDIS_PORT&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6379&lt;/span&gt;
  &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;db_data:/var/lib/postgresql/data&lt;/span&gt;
    &lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;backend&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;POSTGRES_DB&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mydb&lt;/span&gt;
      &lt;span class="na"&gt;POSTGRES_USER&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;myuser&lt;/span&gt;
      &lt;span class="na"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mypassword&lt;/span&gt;
  &lt;span class="na"&gt;redis&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;redis&lt;/span&gt;
    &lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;backend&lt;/span&gt;
  &lt;span class="na"&gt;nginx&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;80:80"&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;443:443"&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;./nginx.conf:/etc/nginx/nginx.conf&lt;/span&gt;
    &lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;frontend&lt;/span&gt;

&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;db_data&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

&lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;frontend&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;backend&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
