---
# System prepended metadata

title: 'Week 18: Containarization With'

---

### Week 18: Containarization With Docker
> By Akinlade Temitope

In software development, one of the most famous phrase is "It works on my machine"

This happens when an application runs perfectly on one system but fails in another because environment, dependencies, configurations e.t.c

Docker was created to solve this problem 

Docker is a platform that allow developers to package their applications along with it's dependecies in lightweight, portable unnit called containers. The containers ensures an application runs exactly the same way whether it is your laptop,a friend's, or a cloud server.

#### Why Are Docker Containers Lightweight And Portable

Before Docker containers, developers used Vm's(Virtual Machines) to create an isolated environment for thier application. A virtual machine runs it's own operating system on top of the host operating sytem which makes it heavy and slow to start compared to containers that shares the host operating system.

#### Dockerfile

A Dockerfile is the blueprint or set of instructions that tells Docker to build an image for your containers.

It contains step like:
1. What base image to use e.g python:3.12-slim
2. What directory to create and change directory into
3. What dependencies to install
4. What file/files to copy into your image
5. What command to run when your container starts

#### Docker Images
Docker images are template that contain everything needed to creat a container and that includes your app, dependecies and configurations

#### Docker Containers
Docker container is a lightweight isolated environment created from an image where your applications run.

These containers are like mini computer on your computer but unlike virtual machines, they do not have thier own operating system, instead they share the host operating system.

#### Docker Engine
Docker engine is the main machine that makes Docker works. It creates, run and manages container behind the scene. 

The Docker engine has three main part:
1. Docker Daemon: This is the background program that does the real work like building images,running containers e.t.c.

2. Docker CLI(Command line interface): These are the commands used to interact with docker e.g docker build, docker run e.t.c. The CLI sends these request to the daemon that does the work.

3. Docker Rest API: This how the CLI and other tools communicate with the daemon 


#### Docker Hub
Docker hub is the official online registry where one can store,download and share images. It a giant library that has already made images like python e.t.c and you can also upload your images there for others to use.

#### Docker Volumes
Docker volumes are persistent data storage for containers that allows data stored outside the container file system, making it acessible to the host or other containers as data is usually lost when a container is stopped or removed.

#### Docker Ports
Ports are virtual identification numbers for applications running on same computer or network to know where to send or receive data.
Since multiple programs can share same ip address, port acts as unique channel that sends traffic to the right application

In Docker, ports allows application running inside a container to be accessible from the host or other containers by mapping container port to host port

#### How Docker Works
Docker follow a simple flow which is to build,run and share
##### BUILDING
First step is to build an image following the blueprint of a Dockerfile and by simply running the command "docker build", it creates an image for your application

Example:
docker build -t app .

The above builds an image named app in the current working directory
##### RUNNING
Second step is to run an instance of that image which is a container and you can do that with the "docker run" command

Example:
docker run -p 8000:8000 app

The above runs your application and makes it accesscible by the host browser.

##### SHARING
Once your image is built and tested, you can share it with others.
This is done by pushing it to a container registry like Docker Hub, where anyone can download and use it. You can do that with "docker tag app username/version" and "docker push username/version"

##### NOTE
You have to be registered on docker hub and logged in to be able to push images to it's registry.


### CONCLUSION
Docker solves this long standing problem of "it works on my machine" and it gives developers the confidence that an application will run the same way everywhere consistently and in uniformity without any unexpected surprises.
