# Docker Basics: A Simple Overview

# 🐋**What is a container ?**

A container is like a small, self-contained box that holds everything an application needs to run: the code, the tools, and the settings.

# 🐋**What is Docker ?**

Docker packages an app and its required software into a container. This container can be moved and run on any computer or server, making sure the app works the same way no matter where it is. It’s a simple way to keep things organized and make sure they run smoothly everywhere.

# 🐋**Docker Architecture ?**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724244381225/fc131a47-4617-43be-b3c1-a2b365c2fc5e.png align="center")

The above picture, clearly indicates that Docker Deamon is brain of Docker.

## 🐋Docker LifeCycle

There are three important things,

1. docker build -&gt; builds docker images from Dockerfile
    
2. docker run -&gt; runs container from docker images
    
3. docker push -&gt; push the container image to public/private regestries to share the docker images.
    

[![Screenshot 2023-02-08 at 4 32 13 PM](https://user-images.githubusercontent.com/43399466/217511949-81f897b2-70ee-41d1-b229-38d0572c54c7.png align="left")](https://user-images.githubusercontent.com/43399466/217511949-81f897b2-70ee-41d1-b229-38d0572c54c7.png)

# 🐋Understanding the terminology

1. #### Docker daemon :
    

The Docker daemon is like the main engine that powers Docker on your computer. It’s a background service that handles everything related to containers, including starting them, stopping them, and managing their resources. Think of it as the manager that makes sure everything runs smoothly and keeps track of your containers, images, and networks.

docker

2. **Docker client :**
    

The Docker client is like the remote control for Docker. It’s a tool you use to send commands to the Docker daemon (the engine that runs Docker).

In short, the Docker client is the interface you interact with to manage your Docker containers and images.

3. #### Docker Desktop :
    

Docker Desktop is a user-friendly application that makes it easy to use Docker on your computer. It provides a graphical interface (GUI) for managing Docker containers and images, so you don’t have to use command-line commands for everything.

4. **Docker registries :**
    

Docker registries are like online storage places where Docker images are kept.

When you build a Docker image (which is like a blueprint for a container), you can upload it to a Docker registry so that others can use it or so you can access it from different computers.

There are two main types :

1. Public Registries
    
2. Private Registries
    
    5. **Dockerfile :**
        
    
    Dockerfile is a file where you provide the steps to build your Docker Image.
    
    6. **Images :**
        

A Docker image is like a snapshot or a template for creating Docker containers. It contains everything needed to run an application, including the code, libraries, and settings.

## 🐋Docker Installing commands

You can create an Ubuntu EC2 Instance on AWS and run the below commands to install docker.

```bash
ubuntu@ip-172-31-46-195:~$ sudo apt update
ubuntu@ip-172-31-46-195:~$ sudo apt install docker.io -y
```

A easy way to verify your Docker installation is by running the below command

```bash
ubuntu@ip-172-31-46-195:~$ docker run hello-world
```

### 🐋Start Docker daemon

You use the below command to verify if the docker daemon is actually started and Active

```bash
ubuntu@ip-172-31-46-195:~$ sudo systemctl status docker
ubuntu@ip-172-31-46-195:~$ sudo systemctl start docker
```

### 🐋Grant Access to your user to run docker commands

To grant access to your user to run the docker command, you should add the user to the Docker Linux group. Docker group is create by default when docker is installed.

```bash
 ubuntu@ip-172-31-46-195:~$ sudo usermod -aG docker ubuntu
```

In the above command `ubuntu` is the name of the user, you can change the username appropriately.

**NOTE:** : You need to logout and login back for the changes to be reflected.

**Docker is Installed, up and running**

Use the same command again, to verify that docker is up and running. /

```bash
ubuntu@ip-172-31-46-195:~$ docker run hello-world
```

# 🐋Write your first Dockerfile

Clone this repository

```bash
ubuntu@ip-172-31-46-195:~$ git clone https://github.com/Gayatrishinde21/Docker-zero-to-hero.git
```

Then Create Dockerfile and app.py using vim command

**Login to Docker**

\[Create an account with https://hub.docker.com/\]

## 🐋Build your first Docker Image

You need to change the username accoringly in the below command

```bash
ubuntu@ip-172-31-46-195:~$ docker build -t gayatris2103/my-first-docker-image:latest .
```

Verify Docker Image is created

```bash
ubuntu@ip-172-31-46-195:~$ docker images
```

Run your First Docker Container

```bash
ubuntu@ip-172-31-46-195:~$ docker run -it abhishekf5/my-first-docker-image
```

### 🐋**Final Output Looks like : )**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724407530041/4f31fec2-1f47-4e7e-ba5d-a1c38bfa0d38.png align="center")
