Forum

Notifications
Clear all

Docker 28-Sep-2024

0
Topic starter

What is Docker ?

     Docker is virtualization Software which make software developing and deployment of applications much easier. Its a customised standard unit that has everything for an application to run. 

What problem Docker solves in Engineering ?

Consider older process of development , we need to install all the required services / tools in each and every environment. 

Docker solves the problem with the concept of containers, With containers we do not have to take the pain of installing services individually, it basically packages everything including , development code, binaries, dependencies and configs and the command is same for all servcies. 

if you have 10 servcies you will just have 10 docker commands.  So you timing on the installation and configuration is drastically reduced and you can spend more time on the development. 

You can run different versions of same application without any conflict .. 

 

to deploy we just have to run docker commands to fetch and run the containers from the artifact. 

 

Difference between Docker & Virtual Machine

 

Docker was Mainly developed for Linux. 

 

-----------------------

OS Application Layer

-----------------------

-----------------------

OS Kernel

-----------------------

-----------------------
Hardware

-----------------------

 

The Docker Architecture

The core components of the Docker architecture include:

  • Docker daemon: The Docker daemon (or “engine”) is the core element of the Docker architecture. It is a background process that manages, builds, and runs Docker containers.
  • Docker client: The Docker client is the interface used to interact with the Docker daemon. It allows users to create and manage Docker images, containers, and networks.
  • Docker image: A Docker image is a read-only template used to build Docker containers. It consists of a set of instructions and files that can be used to build a container from scratch.
  • Docker Registry: The Docker Registry can be used to create repositories for storing and sharing Docker images.
  • Docker network: Docker networks are virtual networks used to connect multiple containers. They allow containers to communicate with each other and with the host system.
  • Docker Compose: Docker Compose is a tool used to define and run multi-container Docker applications. It allows users to define the services that make up their application in a single file.
  • Docker Swarm: As noted above, Swarm is an optional orchestration service that can be used to schedule Docker containers. You can also use an alternative orchestrator, like Kubernetes, with Docker containers.

 

Concepts of Docker Images & Containers?

 

Docker Image contains - Applications , Services and OS Layer (Layer) 

These images will be residing in Artifactory 

one can easily download this image anytime to their local computer . 

Docker Container - Once image is downloaded to local computer , the application needs to run, so it needs to be started 

which means a running instance of a image is called container. 

You can run multiple containers from single image. 

Public & Private Registries. 

How do we get images?

 

Say if we need to run redis database containers , we have images of redis readily available with various versions in Docker Registry. 

Many applications like Redis, MongoDb, Postgress etc.. they have their offical images pushed to these public registries. 

These official images are maintained by Software Authors or in colloboration with Docker Community. 

Docker  itself offers a biggest docker registry called 'Docker Hub' where you can find any of these official images created by individual companies / developers 

 

docker images

docker ps

Lets take example of nginx

docker pull nginx:1.27

docker pull nginx:1.27.1

docker images 

docker run nginx:1.27

docker run -d nginx:1.27

docker logs <container -id>

You can also run container directly from docker hub, without having it locally. 

how do we access the application ? The application is actually running inside the isolated docker network, so it wont be accessible from your computer.... !!!

localhost:80

we should expose the container to our local network 

what we are going to do is Port Binding. 

So the application always run on the standard port 80 inside the container 

Redis will always run on 6379 

stop the running container 

docker stop <container-id>

docker run -d -p <port>:80 nginx:1.27

docker ps

localhost:<port>

Suppose you use DB like MySql which runs on standard port , its always advisable to user the same port while binding 3306:3306

docker ps-a

docker stop 

docker start

docker ps-a

you can also stop / start multiple containers at the same time. 

 

Private Docker Registry

Registry Vs Repositories 

Building your own Docker Container 

 

Docker File 

FROM oraclelinux:7-slim
COPY Test.sh .
#ENTRYPOINT ["./Test.sh"]
RUN yum install -y python3

 

Shell File

#!/bin/sh
echo "-------------------------"
echo "you are on OS"
uname -a
echo "---------------------------"
echo "Python Version "
python3 --version
echo "---------------------------"
echo " Employee Registration "
echo "-------------------------------"
python3 formSubmit.py

 

Python File - formSubmit.py
Name=input("Enter Name : ")
Phone=input("Enter Phone : ")
Email=input("Enter Email : ")
print ("Hello, "+Name+"Your Phone "+Phone+" & Email " + Email +"has been registered")

 

Build 

docker build -t my-app:1.0 ./Dockerfile

docker ps

docker run -d -p 

Image versioning using tags 

 

This topic was modified 1 year ago 2 times by Harish
© Copyright 2024, All rights reserved by HeyCloud Innovations LLP | designed by ColorWhistle | Privacy Policy | Terms and Conditions