🔥Concepts of Docker🧑‍💻
Tags: docker, devops, devjournal, kubernetes
Published: 2022-08-20 14:44:00

firstly before we dive into docker I'll like you to view my article about [containers](https://dev.to/denzubechi/containers-5kh) if you have a little knowlegde concercerning containerization.

In this tutorial you will understand **Docker**,installation,its core concepts and how it revolutionizes software development. Learn container creation, Dockerfiles, image building, and container management. Discover how Docker ensures consistent environments from development to production. Get ready to elevate your development skills with Docker!

## What is Docker?🧐
Docker is a widely acclaimed open-source container runtime tool that revolutionizes the way we build, test, and run containers. It serves as both a container system and a prominent company, leading the containerization movement.

As a container system, Docker enables developers to package applications and their dependencies into a standardized, lightweight, and portable unit called a container. These containers ensure consistent performance across various environments, from development to production, eliminating the "it works on my machine" conundrum. Docker simplifies the deployment process, making it seamless and efficient.

Beyond being a technology, Docker is also the name of the company that played a pivotal role in popularizing containerization. The company's contributions have had a profound impact on software development and DevOps practices, empowering teams worldwide to embrace containers for scalable and agile application deployment.
Docker revolutionizes software development with containerization, isolating applications and dependencies in **Docker Images.** These images run as portable and lightweight **Docker Containers**, ensuring consistent execution. The "Dockerfile" defines image creation instructions, and [Docker Hub](https://hub.docker.com/) offers a repository for sharing pre-built images. **Docker Compose** simplifies managing multi-container applications, while **Container Orchestration** tools like Kubernetes enable scaling and management. Docker's networking and volume features enhance communication and data persistence. Master these fundamental Docker concepts for efficient and scalable application development.

Using Docker, you can create containers with both Linux and Windows kernels, although Windows containers are only available if you are running a Windows machine. In either case (Linux/Windows), you will have to install Docker on your local machine. **Installing Docker means installing ** [Docker Desktop](https://docs.docker.com/desktop/), a command-line utility.

## How to install Docker Desktop? 🧑‍🔧 

Installing Docker means installing Docker Desktop, a command-line utility. There are installers available for all the major operating systems: Linux, OSX, and Windows. You can find installers at either of the below links which are part of the official Docker documentation:

- [Get Docker](https://docs.docker.com/v17.12/install/)

- [Docker Desktop Overview](https://docs.docker.com/desktop/)
Once docker is installed you should be able to continue!

### 1. Docker for Mac
Upon clicking on either of the links above, you will be redirected to [Docker Desktop for Mac page](https://hub.docker.com/editions/community/docker-ce-desktop-mac/).
The requirement is that your macOS must be version 10.14 or newer. This page also has the installation instructions available for you.

![Successful installation of docker on mac](https://global.discourse-cdn.com/docker/original/3X/7/f/7f03c07cd0613ffbb84792fd7e26c199fdbabf37.jpeg)

> Succcessful Installation of Docker Desktop on Mac

### 2. Docker for Windows 10 Professional or Enterprise (64-bit)
- Click on one of the provided links, which will take you to the [Docker Desktop installation page for Windows ](https://docs.docker.com/docker-for-windows/install/#system-requirements). Make sure to check the System Requirements listed there to ensure compatibility.

- Once on the [Docker Desktop page](https://hub.docker.com/editions/community/docker-ce-desktop-windows/), click on the download link for the .exe installer.

- After the download is complete, run the .exe file with Administrator privileges.

- Follow the prompts to complete the installation process.

- During the installation, pay attention to the Configuration page. It is crucial to select the "Enable Hyper-V Windows Features" option, as Docker on Windows relies on Hyper-V for container virtualization.

By following these steps, you will successfully install Docker Desktop on your Windows 10 Professional or Enterprise system. Docker Desktop provides an intuitive interface for managing and running containers on your Windows machine, enabling you to utilize the power of containerization in your development workflow.

### 3. Docker for Windows 11/10 Home (64-bit)
- If you are using Windows 11/10 Home, the process of installing [Docker Desktop](https://docs.docker.com/docker-for-windows/install-windows-home/) involves an additional step. Before installing Docker, you must first install and enable the [Windows Subsystem for Linux (WSL) 2](https://docs.microsoft.com/en-us/windows/wsl/install-win10). This is necessary to ensure that Docker runs smoothly on your system.

- To install WSL2, you can refer to the Appendix page for detailed instructions. Once WSL2 is set up on your machine, you can proceed with the regular Docker installation process.

- Visit the [Docker Desktop for Windows page](https://hub.docker.com/editions/community/docker-ce-desktop-windows/) and download the .exe installer. After the download is complete, run the .exe file as an Administrator. Follow the on-screen prompts to complete the Docker Desktop installation.

- During the installation, remember to check the "Enable Hyper-V Windows Features" option on the Configuration page. This step is crucial as Docker relies on Hyper-V for container virtualization.

By installing WSL2 and Docker Desktop, you will unlock the full potential of containerization on your Windows 10 Home machine. Embrace the power of Docker to build, test, and run containers effortlessly, enhancing your software development experience.
![Enable WSL features](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwk95fuk9nyv6xu1the1.png)
`Importantly, ensure to check the "Enable WSL 2 Features" option on the Configuration page.`

![WSL](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bemzspxmwwzy9fka92vh.png)
`Restart your machine allowing the Docker Desktop to take effect, and launch the WSL from the Start menu.`

### 4. Verify the Docker installation
You can run either of the following commands in your Mac terminal / WSL terminal:

```
# to check the version
docker version
# to verify that Docker can pull and run images (we will talk more about images next)
docker run hello-world 

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4bwqxexm6xgvihibu8ep.png)
> Verify using docker run hello-world in your Mac terminal

Now let's dive into the Concepts of **Docker**!🤩
## Docker Architecture
The **Docker architecture** is a well-structured and flexible system that empowers containerization. At its core is the Docker Daemon (dockerd), the engine running on the host system. It manages Docker objects like images, containers, networks, and volumes, ensuring proper isolation and resource utilization. Users interact with the Docker Daemon through the Docker Client (docker), a command-line interface (CLI) tool. **Docker Images** serve as read-only templates, containing the application code, dependencies, and configurations necessary to run an application. Running instances of these images are called Docker Containers, offering isolated and efficient runtime environments. **Docker Registries** store Docker Images, with Docker Hub being the primary public repository. Docker provides built-in networking capabilities and Docker Volumes for data persistence. Docker Compose simplifies managing multi-container applications using a YAML file, and Docker Swarm facilitates container clustering and orchestration for scalability and high availability. The comprehensive Docker architecture streamlines the development, deployment, and management of containerized applications, revolutionizing modern software development workflows.

![Docker Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fwsinv0fodmel7znxzwu.jpg)


Let's go deeper!😃🤓
**1. Docker Engine**
The heart of Docker is the Docker Engine, a powerful application comprising three essential components: the Docker daemon, an API, and a client.

The Docker daemon operates as a server, responsible for managing various aspects such as images, containers, networks, and volumes. On the other hand, the Docker client serves as the user interface, facilitating interactions with Docker through the command line. Most of your Docker-related tasks will be executed at the command line using this CLI client.

The Docker client communicates with the Docker daemon through a command line API, creating a seamless bridge between user commands and the daemon's functionality. This communication ensures that users can easily manage Docker resources, create and run containers, and perform other operations efficiently.

![docker engine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ppfmzvyy56ak5awp73y.png)

**2. Docker Image**
A Docker image is the set of instructions for creating a container. The image typically includes a file system and the parameters that will be used for the container.

_Images are comprised of multiple layers. Each layer contains specific software._

You can create a custom Docker image for a specific application. Start with a standardized [parent image](https://docs.docker.com/glossary/?term=parent%20image) as the base layer. The parent image often contains the file system of a particular operating system, such as Ubuntu 18.04. Then add an additional layer to the image, on top of the base layer. You can add your application files to this additional layer. You can even add multiple additional layers, and distribute your application files across different layers, as appropriate for your needs.



**3. Docker Container**
Docker container is just the Docker-specific implementation of the concept. In practice, Docker containers are created from Docker images - a container is a runnable instance of an image. Note that since the image is a set of instructions for creating a container, multiple containers can be created from the same image.

**4. Docker Registries**
[Docker registries](https://docs.docker.com/registry/) are essential components of the Docker ecosystem, serving as repositories for storing, sharing, and distributing Docker Images. They play a critical role in the containerization process, allowing users to access pre-built images, collaborate with others, and manage private images securely. 

##How does it work? 🧑🏼‍💻 👨🏼‍💻
Let me give you an overview of the flow of execution for creating a container:

> **Dockerfile → Docker Image → Docker container**

**1. Write a Dockerfile** 🧑🏼‍💻 
> It is a text document that contains the commands a user would execute on the command line to assemble an image. In this file, you can specify the necessary environments and dependencies. For example, see a Dockerfile below:
```
# Pull the "tomcat" image. The community maintains this image. 
FROM tomcat 
# Copy all files present in the current folder to the "/usr/local/tomcat/webapps"  folder 
COPY ./*.* /usr/local/tomcat/webapps

```
>In the example above, every time you create a container, it will have the tomcat web server installed. In addition, all the contents of the current directory will also be copied to the /usr/local/tomcat/webapps folder of each container.

**1.Build an Image:** 🧑🏼‍💻 
> Use the docker `build command` to build an image from the Dockerfile. Usually, we execute this command from the same directory where the Dockerfile is present.

```
# This command will look for a Dockerfile in the `pwd`, and create myImage
docker build  --tag myImage  [OPTIONS] path_where_to_store_the_image 

```
>You can store your images online at DockerHub as well, so that you/anyone can "pull" them on any other machine, anytime. We can even use the pre-created Docker images maintained by the community. e.g `docker pull tomcat:latest`

**2. Create and run a Container**
> After creating an image, you can use it to create as many Containers as you want on any platform. Each container will have the same environment and dependencies to run a copy of your application. The following command creates and runs a new container: `docker run --name myContainer myImage`

## Let's wrap it up 🎁
In this tutorial , you’ve learned about Docker, which is the most common container platform. You’ve also learnt it's installation, introduced to concepts related to how Docker works, including the

> - Docker daemon,
- Docker client,
- Docker images and containers, and
- the Docker Registry.