# Diving into Docker: A Comprehensive Series on Containerization.

### Introduction

In today's rapidly evolving digital landscape, staying ahead of the curve is a daily challenge. Efficiency, consistency, and portability are the guiding principles for developers, operations professionals, and anyone involved in the software development lifecycle. This is where [Docker](https://www.docker.com/), the innovative containerization platform, comes into play.

Welcome to our new blog series, "**Diving into** [Docker](https://docs.docker.com/get-started/overview/)**: A Comprehensive Series on Containerization.**" This series will take you on a tour through the intriguing world of [Docker](https://www.docker.com/products/docker-desktop/), studying its fundamental principles, components, and real-world applications.

Whether you're a developer looking to streamline your workflow, an operations professional seeking to optimize infrastructure management, or simply curious about containerization, this series has something for you.

### Why [Docker](https://docs.docker.com/) Is Important?

[Docker](https://aws.amazon.com/docker/) simplifies application development and deployment by encapsulating applications into portable containers. It enhances consistency, and reliability, and simplifies the development and deployment process.

### What to Look For in Our [Docker](https://en.wikipedia.org/wiki/Docker_(software)) Series

* **Getting Started with** [**Docker**](https://opensource.com/resources/what-docker)
    
* [**Docker**](https://www.ibm.com/topics/docker) **Images and** [**Dockerfiles**](https://www.zdnet.com/article/what-is-docker-and-why-is-it-so-darn-popular/)
    
* [**Docker**](https://github.com/docker) **Registries**
    
* [**Docker**](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker) **Compose**
    
* **Container Orchestration**
    
* **Best Practices and Tips**
    

**Getting Started with** [**Docker**](https://www.techtarget.com/searchitoperations/definition/Docker)**:** We'll start with the fundamentals, demonstrating how to install [Docker](https://twitter.com/Docker) and launch your first container. This section is for you if you're new to [Docker](https://www.infoworld.com/article/3204171/what-is-docker-the-spark-for-the-container-revolution.html) or want to brush up on your abilities.

[**Docker**](https://www.youtube.com/watch?v=pg19Z8LL06w&ab_channel=TechWorldwithNana) **Images and** [**Dockerfiles**](https://www.youtube.com/user/dockerrun)**:** You'll learn how to use [Dockerfiles](https://marketplace.digitalocean.com/apps/docker) to construct custom [Docker images](https://www.geeksforgeeks.org/introduction-to-docker/), allowing you to package your apps and dependencies in a reusable and efficient manner.

[**Docker**](https://www.simplilearn.com/tutorials/docker-tutorial/what-is-docker-container) **Registries:** Learn how [Docker](https://docker-curriculum.com/) registries, such as the popular [Docker Hub](https://blog.runpod.io/diy-deep-learning-docker-container/?utm_term=&utm_campaign=Serverless+GPU&utm_source=adwords&utm_medium=ppc&hsa_acc=4558579452&hsa_cam=20156995097&hsa_grp=&hsa_ad=&hsa_src=x&hsa_tgt=&hsa_kw=&hsa_mt=&hsa_net=adwords&hsa_ver=3&gclid=CjwKCAjw6p-oBhAYEiwAgg2PgubnQUSvK9pAdA7HILRfFuoH0pcLUtiCVkfRK4VPCRTRm9iPN68caBoCg00QAvD_BwE), act as image repositories. We'll also look at creating your private register for increased control and protection.

[**Docker**](https://www.udemy.com/course/docker-mastery/) **Compose:** Dive into [Docker Compose](https://www.simplilearn.com/tutorials/docker-tutorial/what-is-docker-container), a tool for managing multi-container applications. We'll teach you how to use basic YAML files to design complicated application architectures.

**Container Orchestration:** Learn how [Docker](https://labs.play-with-docker.com/) works seamlessly with container orchestration technologies such as Kubernetes and Docker Swarm to manage and grow containers in dynamic settings.

**Real-World Use Cases:** Real-world examples of how businesses use [Docker](https://www.tutorialspoint.com/docker/index.htm) to expedite development workflows, optimize production environments, and improve DevOps methods are provided.

**Best Practices and Tips:** We'll discuss best practices and practical ideas for using [Docker](https://www.sumologic.com/glossary/docker/) in your applications.

## **Getting Started with** [**Docker**](https://learn.microsoft.com/en-us/dotnet/architecture/microservices/container-docker-introduction/docker-defined) **Windows**

* Clone the repository for getting-started apps.
    

```bash
git clone https://github.com/docker/getting-started-app.git
```

* The cloned repository contains various files and sub-directories that can be viewed.
    

```makefile
getting-started-app/
package.json
README.md
spec/
src/
yarn.lock
```

* Make sure that you are in the **getting-started-app** directory.
    
* The path to **getting-started-app** should be replaced with the path to your **getting-started-app** directory.
    

```makefile
cd \path\to\getting-started-app
```

* Make a new file called [Dockerfile](https://www.youtube.com/watch?v=rOTqprHv1YE&ab_channel=Simplilearn).
    

```makefile
type nul > Dockerfile
```

* Add the following contents to the [Dockerfile](https://www.youtube.com/watch?v=3c-iBn73dDE&ab_channel=TechWorldwithNana) using a text editor or code editor
    

```makefile
# syntax=docker/dockerfile:1

FROM node:18-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000
```

* Build the image using the following commands
    

```makefile
$ cd /path/to/getting-started-app
```

* Make sure you're in the getting-started-app directory in the terminal.
    
* **<mark>/path/to/getting-started-app</mark>** should be replaced with the path to your **getting-started-app** directory.
    

```bash
$ docker build -t getting-started
```

* The docker build command uses the [Dockerfile](https://www.synology.com/en-in/dsm/feature/docker) to create a new image, downloading layers as instructed.
    
* The [Dockerfile](https://wiki.archlinux.org/title/docker) then copies the application's dependencies and uses yarn to install them.
    
* The CMD directive specifies the default command for container startup.
    
* The -t flag tags the final image, allowing reference to it when running a container.
    

### **Start an app container**

* Use the [docker](https://www.aquasec.com/cloud-native-academy/docker-container/) run command to start your container and give the name of the freshly produced image.
    

```bash
docker run -dp 127.0.0.1:3000:3000 getting-started
```

* The -d flag detaches the container, while the -p flag publishes a port mapping between the host and the [container](https://docs.n8n.io/hosting/installation/docker/), taking a string value in HOST:CONTAINER format.
    

**This ensures application access from the host.**

Open the web browser to [http://localhost:3000open\_in\_new](http://localhost:3000open_in_new). You should see your app.

## Linux-based system instructions

### Step 1: Installing the latest version of [Docker](https://cloudacademy.com/course/introduction-to-docker-2/what-is-docker-1/?utm_feeditemid=&utm_device=c&utm_term=&utm_campaign=%5BSearch%5D+DSA+-+All+Website+-+India&utm_source=google&utm_medium=ppc&hsa_acc=5890858304&hsa_cam=13996404894&hsa_grp=128133670034&hsa_ad=651406237901&hsa_src=g&hsa_tgt=aud-979686815246:dsa-19959388920&hsa_kw=&hsa_mt=&hsa_net=adwords&hsa_ver=3&gclid=CjwKCAjw6p-oBhAYEiwAgg2PgjEZl4y5k94oJVrtoYgFX9keTKIhFsU-yNVrvszAWiScJ9wGNrhlOBoCawUQAvD_BwE)

* Update your package repository to verify you are installing the most recent version of [Docker](https://www.linkedin.com/company/docker/)
    

```bash
sudo apt update
```

### Install [Docker](https://towardsdatascience.com/docker-for-absolute-beginners-what-is-docker-and-how-to-use-it-examples-3d3b11efd830) dependencies

```bash
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
```

### Install the [Docker](https://stackify.com/docker-tutorial/) GPG key on your machine

```bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
```

### Install the [Docker](https://www.toptal.com/devops/getting-started-with-docker-simplifying-devops) repository

```bash
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```

### Refresh your package for the Updated repository.

```bash
sudo apt update
```

### Install [Docker](https://www.jenkins.io/doc/book/installing/docker/)

```bash
sudo apt install -y docker-ce docker-ce-cli containerd.io
```

### Start and enable the [Docker](https://devopscube.com/what-is-docker/) service

```bash
sudo systemctl start docker
sudo systemctl enable docker
```

### Verify that [Docker](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html)

* Verify that [Docker](https://www.edureka.co/blog/docker-container/) is installed and running by running the following command
    

```bash
sudo docker --version
```

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html" style="pointer-events: none">Docker</a> is a powerful platform for <a target="_blank" rel="noopener noreferrer nofollow" href="https://spring.io/guides/topicals/spring-boot-docker/" style="pointer-events: none">containerization</a> that encapsulates applications and their dependencies into portable, isolated environments called <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.keycloak.org/getting-started/getting-started-docker" style="pointer-events: none"><strong>containers</strong></a>.</div>
</div>

### Step 2: **Launch Your First** [**Container**](https://www.sdxcentral.com/cloud/containers/definitions/what-is-docker-container/)

* Run `sudo docker run hello-world`.
    
* Docker downloads and runs the "Hello World" image.
    
* You'll see a confirmation message if [Docker](https://www.amazon.in/s?k=docker&adgrpid=54382083050&ext_vrnc=hi&hvadid=590962682792&hvdev=c&hvlocphy=9299829&hvnetw=g&hvqmt=e&hvrand=2222826908066043209&hvtargid=kwd-43721580&hydadcr=27151_2267868&tag=googinhydr1-21&ref=pd_sl_6a4no49rha_e) is installed correctly.
    

```bash
sudo docker run hello-world
```

## Key concepts and components related to Docker

### **What is a Container?**

*"A* [*container*](https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html) *is an abstraction at the application layer that groups together code and dependencies.* [*Containers*](https://docs.strapi.io/dev-docs/installation/docker) *virtualize only the host operating system rather than the full physical computer."*

A [container](https://www.cisecurity.org/benchmark/docker) is a lightweight, executable software package that includes code, runtime, system tools, libraries, and settings, providing a consistent environment for applications across different computing environments.

### What are the key advantages of using containers, and how do they address the common "it works on my machine" problem in software development?

When you try to run it on a colleague's machine or deploy it to a cloud server, you run into compatibility difficulties, dependency conflicts, or unexpected behavior. This is known as the "it works on my machine" dilemma in software development.

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Containers solve this problem by encapsulating the application and all its dependencies in a self-contained unit called a container.</div>
</div>

* ### Isolation
    

[Containerization](https://www.docker.com/resources/what-container/) technology creates isolated environments, allowing multiple containers to coexist on the same host without interfering with each other, unlike traditional VMs.

* ### Portability
    

[Containers](https://www.docker.com/) are portable, allowing applications and dependencies to be run on any system that supports containerization, ensuring consistency across different infrastructures and operating systems.

* ### Self-sufficiency
    

A container provides all necessary application components, eliminating the need for host system dependencies, and simplifying application management and deployment without concerns about conflicting libraries or missing dependencies.

* ### Reproducibility
    

[Containers](https://docs.docker.com/get-started/overview/) are created using [Dockerfiles](https://www.jetbrains.com/help/pycharm/docker.html) or container manifests, which specify the [container](https://hub.docker.com/)'s contents and configuration, ensuring consistent behavior across different environments.

* ### Efficiency
    

[Containers](https://docs.docker.com/engine/reference/commandline/container/) are lightweight, resource-efficient, and quick to start, making them ideal for microservices architectures and scaling applications as needed.

[Containers](https://docs.docker.com/get-started/) are essential for modern software development, allowing developers to focus on code while operations teams manage applications. Kubernetes automates tasks in dynamic environments.

to be continued...

<details data-node-type="hn-details-summary"><summary>Summary</summary><div data-type="detailsContent">The blog series "Diving into <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.freecodecamp.org/news/the-docker-handbook/" style="pointer-events: none">Docker</a>: A Comprehensive Series on <a target="_blank" rel="noopener noreferrer nofollow" href="https://stackoverflow.com/questions/tagged/docker" style="pointer-events: none">Containerization</a>" delves into <a target="_blank" rel="noopener noreferrer nofollow" href="https://cognitiveclass.ai/courses/docker-essentials" style="pointer-events: none">Docker</a>'s principles, components, and real-world applications. It covers Getting Started with <a target="_blank" rel="noopener noreferrer nofollow" href="https://medium.com/codingthesmartway-com-blog/docker-beginners-guide-part-1-images-containers-6f3507fffc98" style="pointer-events: none">Docker</a>, <a target="_blank" rel="noopener noreferrer nofollow" href="https://kodekloud.com/courses/docker-for-the-absolute-beginner/" style="pointer-events: none">Docker</a> Images and <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.manning.com/books/docker-in-action" style="pointer-events: none">Dockerfiles</a>, <a target="_blank" rel="noopener noreferrer nofollow" href="https://docs.datadoghq.com/containers/docker/?tab=standard" style="pointer-events: none">Docker</a> Registries, <a target="_blank" rel="noopener noreferrer nofollow" href="https://docs.gitlab.com/runner/executors/docker.html" style="pointer-events: none">Docker </a>Compose, <a target="_blank" rel="noopener noreferrer nofollow" href="https://learn.microsoft.com/en-us/dotnet/architecture/microservices/container-docker-introduction/" style="pointer-events: none">Container </a>Orchestration, Real-World Use Cases, and Best Practices.</div></details>

Stay tuned for the upcoming articles in the series, where we'll discuss more interesting topics related to [Docker](https://docs.appsmith.com/getting-started/setup/installation-guides/docker). Subscribe to our channel to ensure you don't miss any part of this enlightening journey!

Thank you for reading our blog. Our top priority is your success and satisfaction. We are ready to assist with any questions or additional help.

Warm regards,

[**Kamilla Preeti Samuel,**](https://www.linkedin.com/in/preeti-samuel-kamilla-5a247962/)

**Content Editor**

[**ByteScrum Technologies Private Limited!**](https://www.bytescrum.com/) 🙏
