# Day 11: Getting started with Docker

## What is a container?

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.

## Why are containers lightweight?

Containers are lightweight because they use containerization technology, which allows them to share the host operating system's kernel and libraries while providing isolation for the application and its dependencies. This results in a smaller footprint compared to traditional virtual machines, as the containers do not need to include a full operating system. Additionally, Docker containers are designed to be minimal, only including what is necessary for the application to run, reducing their size.

## Docker

### What is Docker?

Docker is a containerization platform that provides an easy way to containerize your applications, which means, using Docker you can build container images, run the images to create containers and also push these containers to container registries such as DockerHub, [Quay.io](http://Quay.io), and so on.

In simple words, you can understand as `containerization is a concept or technology` and `Docker Implements Containerization`.

### Docker LifeCycle

We can use the above Image as a reference to understand the lifecycle of Docker.

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 registries to share the docker images.
    

**Building a Docker Image**

Dockerfile ＞ Docker Image ＞ Docker Container ＞ Access the App

Step 1 - Create a new directory **mkdir myapp** **cd myapp**

Step 2 - Create a file called "index.html" **echo "Hello, world!" ＞ index.html**

Step 3 - Create a file named Dockerfile **touch Dockerfile**

Step 4 - Open the "Dockerfile" file in a text editor and add the following lines: FROM nginx COPY index.html /usr/share/nginx/html

This Dockerfile defines a new Docker image that - uses the official nginx image as a base - then copy the index.html file to the appropriate location in the image.

A Dockerfile is a text file with instructions to build a Docker Image When we run a Dockerfile, Docker image is created When we run the docker image, containers are created

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1692378005911/807f2e2a-a303-4ad2-896e-4ffb6e857342.png align="center")

* [Dockerfile ＞Docker Image ＞ Docker Container](https://www.youtube.com/watch?v=C-bX86AgyiA)
    
* [How to Push and Pull a Docker Image from Docker Hub](https://www.youtube.com/watch?v=EIHY_CY5J0k)
