ANIL DOLLOR,
Sr. Software Engineer,
DOLLORINFOTECH, INDIA
+91-7999452711(WhatsApp)
About Me
● Sr. Software Engineer - DOLLOR INFOTECH
● YouTuber - OKLABS Channel
● Professor - Gyanodaya College, Neemuch,MP, INDIA
● dollorinfotech@gmail.com
● https://www.linkedin.com/in/anildalar
● https://github.com/anildalar
Join my Youtube Channel
https://youtube.com/oklabsguru
Why we are learning Docker ?
1. Docker gives you virtual OS Environment.
2. MicroService App runs on Isolated Environment
3. Deliver the application faster.
No need worry about "Production/Test release failures"
Now you can't say
"Hey its working on my Local but not sure why its not working on production/test server :)".
4. Docker gives you a guaranteed same development environment on all 3 phase
1. Development
2. Testing
3. Production
Who should learn Docker
● Developers
● DevOps Engineer
● Linux System Administrators
● Data Scientist
https://www.docker.com/
https://hub.docker.com/
Pre-requisites
Linux basics commands
Docker Architecture
Docker Architecture Consist of 3 Components
1. Docker Client ( Tool/Software that you install on your machine)
2. Docker Daemon ( Service that run inside your machine as background service)
3. Docker Registry (Website/Cloud App)
Docker Engine Architecture
Practical Lab Assignment
1. We will Create a Docker Hub Account
2. Download the image
3. Build Container from image
4. Run the Container
6. Go inside the container
7. Exit from container
8. Stop the Container/ Re Run it
9. Upload the image to docker hub.
9.1 Public Mode
9.2 Private Mode
10. Student will download my Docker Hub image onto their machine
DOCKER COMMANDS
Download the image
Syntax
docker pull <imagename>:<tagname>
Example
docker pull node:latest
DOCKER COMMANDS
Display the downloaded images
Example
docker images
or
docker image ls
DOCKER COMMANDS
Display the details of image
Syntax
docker inspect <imagename>
Example
docker image python
DOCKER COMMANDS
Remove docker image
Example
docker rmi <ImageId>
rmi = Remove Image
DOCKER COMMANDS
Create Container from image
Syntax
docker container create --name <containerName> <baseimage>
or
docker create --name <containerName> <baseimage>
Syntax
docker container create --name nginx_base -p 80:80 nginx:alpine
docker create --name nginx_base -p 80:80 nginx:alpine
DOCKER COMMANDS
Run the Container
Syntax
docker run <flags> <containerName> <shell>
Example
docker run -dp 80:80 myimage
-d = -d flag to run the container in detached mode (background service)
-p = -p flag is used to open the port of application
DOCKER COMMANDS
Go inside the container
Syntax
docker exec <flag> <containerId> <shell>
Example
docker exec -it #283aas9878a /bin/bash
-i = --interactive or -i flag to indicate that the container’s STDIN should be opened.
-t = -t flag to allocate a psuedo-TTY to be able to run interactive commands
DOCKER COMMANDS
Listing All Running Containers
docker ps
DOCKER COMMANDS
Listing All Stopped or Started Containers
docker ps -a
Copy a file from the host to a container
Syntax
docker cp TARGET CONTAINER:SOURCE
Example
docker cp index.html web:/index.html
Copy a file from a container to the host
Syntax
docker cp CONTAINER:SOURCE TARGET
Example
docker cp web:/index.html index.html
It's hard to start with fresh OS images
Better to use Technology Specific Images
Suppose if you are a Node Js Developer better to start with node image instead of
using ubuntu and install node in the image.
Will be waste of our time . So we will use
docker pull node:latest
Suppose you are a Python Developer the your will use
docker pull python:latest
Ports
Ports are communication path of a
operating system
(i.e container)
PORT?
Open
Close
Understand Dockerfile
Build Your Own Image/Container
You can build your own container/image using a “Dockerfile”
Syntax
docker image build -t ImageName:TagName dir
or
docker build -t ImageName:TagName dir
Example
docker build -t myimage:1.0.0 .
Docker - File
Dockerfile Sample (NodeJS)
FROM node
WORKDIR /var/www/rtc_app
COPY . .
RUN npm install
EXPOSE 5000
CMD ["node","backend/server.js"]
Dockerfile Sample (Python)
FROM python:latest
WORKDIR /home
COPY . .
RUN python -m pip install -r requirements.txt
EXPOSE 8000
RUN django-admin startproject anil .
CMD [ "python","manage.py","runserver","0.0.0.0:8000" ]
Biggest problem for us now.
"I want to work in host OS but wanted to
see the changes in running container"
The Next Topic "Volume/Mounting" will
give this answer
Volume Mounting
Sharing FileSystem with container.
There are 2 Ways
1. Using Command line
2. Using Docker compose file
Note
You can't mount a VOLUME in a Dockerfile specifying both source (host)
and destination (container) paths.
This is because this idea does not fit the basic concept that Docker image is
portable and independent of host.
How container can talk to each other ?
Application Database
By default containers are isolated, means all
ports are closed, so container can not talk to
each other
But ….Some way by which container can talk to
each other.
There are 2 Ways
1. Expose the port of container, and allow containers to talk
to each other with host OS. ( Not Recommended )
2. Put the containers inside one network. ( Recommended )
Docker Compose
1. Docker compose is a tool which read a docker-compose.yml file.
2. Build the container according to the commands/instructions
provided in the file.
Docker compose ( Installation not required on windows)
Docker compose ( Installation is required on linux )
YAML: YAML Ain't Markup Language
Best Practice
One service per container
version: '3.9'
services:
service1:
container_name: node_cont
build: .
depends_on:
- db
ports:
- '5000:5000'
volumes:
- .:/app
- /app/node_modules
db:
image: 'postgres:latest'
container_name: db_cont
ports:
- '5432:5432'
environment:
POSTGRES_PASSWORD: 'mysecretpassword'
POSTGRES_USER: 'oklabs'
DOCKER COMMANDS
Push image to Docker Hub
docker login
docker tag firstimage YOUR_DOCKERHUB_NAME/firstimage
docker push YOUR_DOCKERHUB_NAME/firstimage
Note:-
docker image build read and build the "Dockerfile" file
docker-compose read and build the "docker-compose.yml" file
docker build Dockerfile
docker-compose docker-compose.yml
Build
Look
Build
Look
Container
Docker Terminology
Docker Image
Docker Container
Docker Daemon
Docker Registry
Docker Client
Dockerfile
Database
# DB Name DB Type DB GUI PORT
Links
1 MongoDB NoSQL
MongoDB
Compass
27017
https://www.mongodb.com/try/
download/compass
2 Redis DB NoSQL Redis Insight 6379
https://redis.com/redis-enterpri
se/redis-insight/
3 MySQL SQL Workbench 3306
https://dev.mysql.com/downlo
ads/workbench/
4 PostGres SQL PgAdmin 5432
https://www.pgadmin.org/dow
nload/
Docker Assignment
NoSQL DBs
Download mongo image and implement the nodejs / python code.
Download redis image and implement the nodejs/python code.
SQL DBs
Download mysql image and implement the nodejs / python code.
Download postgres image and implement the nodejs / python code.
Imp Commands
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3306:3306 -d mysql:tag
docker run --name postgres-db -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres
Remember
Stop the database services in Host Machine
Solution for windows :
1. Stop docker container
2. win + r and type services.msc
3. Find postgres/mongo services and stop
4. Start your container again
Notes
By default containers are isolated, means all ports are closed.
We can open the port in 3 Ways
1. using EXPOSE command in Dockerfile.
2. Using --expose flag in docker run command.
3. Using docker-compose
So external service can talk to container and vice versa.
docker run = docker pull + docker create + docker start
nodemon -L <script_file>
docker logs -f <container_name>
Q & A
How to check which containers are running ? docker ps
Write down any 5 Dockerfile commands?
Which is the first Dockerfile command ? FROM
What is the command to stop all running container ? docker stop $(docker ps -q)
What is the command to stop all container ? docker stop $(docker ps -a -q)
What is the command to remove all containers ? docker rm $(docker ps -a -q)
What is the command to remove the image? docker rmi imagename/imageId
Useful docker commands
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker-compose up --build -d
Do you what to learn Software Development ?
I have 10 Yrs of Teaching and Software industry Experience.
Your can contact me on whatsApp +91-7999452711 or anildalar8888@gmail.com.
I teach my students across the globe.
Classes are daily basis Monday to Saturday 2 Hr Daily,
Daily Assignment, Daily Quiz, Daily Practice .
After the Training you will get Training and Experience Certifications form OKLABS
and DOLLORINFOTECH respectively .
100% placement after the training..
Course Details
GIT, HTML5,CSS3,BootStrap,JS,JQuery, ReactJS ,NodeJS,ExpressJS,
MongoDB,MySQL,Redis,PostGres (All Dbs SQL n NoSQL), Docker,NgRok
Live Project Deployment
Placement IN MNC
Certificates
1. OKLABS Training Certificate (1 Year)
1. DOLLOR INFOTECH Experience Certificate (1 Year)
FullStack 1K USD
Student Can Pay in 3 EMI
333USD x 3
In order to enroll You Must pay 1 EMI
All Videos will be Private VIdeos.
1. Daily Class (Monday to Saturday 8:30 AM IST - 9:30 AM IST)
2. Daily Assignment
3. Daily Quiz
4. You will be added into the WhatSAPP Group for Discussion
5. You can Call for Doubts and have anydesk session for discussion
Docker Introduction.pdf

Docker Introduction.pdf

  • 1.
    ANIL DOLLOR, Sr. SoftwareEngineer, DOLLORINFOTECH, INDIA +91-7999452711(WhatsApp)
  • 2.
    About Me ● Sr.Software Engineer - DOLLOR INFOTECH ● YouTuber - OKLABS Channel ● Professor - Gyanodaya College, Neemuch,MP, INDIA ● dollorinfotech@gmail.com ● https://www.linkedin.com/in/anildalar ● https://github.com/anildalar
  • 3.
    Join my YoutubeChannel https://youtube.com/oklabsguru
  • 4.
    Why we arelearning Docker ? 1. Docker gives you virtual OS Environment. 2. MicroService App runs on Isolated Environment 3. Deliver the application faster. No need worry about "Production/Test release failures" Now you can't say "Hey its working on my Local but not sure why its not working on production/test server :)". 4. Docker gives you a guaranteed same development environment on all 3 phase 1. Development 2. Testing 3. Production
  • 5.
    Who should learnDocker ● Developers ● DevOps Engineer ● Linux System Administrators ● Data Scientist
  • 7.
  • 8.
  • 10.
    Docker Architecture Docker ArchitectureConsist of 3 Components 1. Docker Client ( Tool/Software that you install on your machine) 2. Docker Daemon ( Service that run inside your machine as background service) 3. Docker Registry (Website/Cloud App)
  • 12.
  • 15.
    Practical Lab Assignment 1.We will Create a Docker Hub Account 2. Download the image 3. Build Container from image 4. Run the Container 6. Go inside the container 7. Exit from container 8. Stop the Container/ Re Run it 9. Upload the image to docker hub. 9.1 Public Mode 9.2 Private Mode 10. Student will download my Docker Hub image onto their machine
  • 16.
    DOCKER COMMANDS Download theimage Syntax docker pull <imagename>:<tagname> Example docker pull node:latest
  • 17.
    DOCKER COMMANDS Display thedownloaded images Example docker images or docker image ls
  • 18.
    DOCKER COMMANDS Display thedetails of image Syntax docker inspect <imagename> Example docker image python
  • 19.
    DOCKER COMMANDS Remove dockerimage Example docker rmi <ImageId> rmi = Remove Image
  • 20.
    DOCKER COMMANDS Create Containerfrom image Syntax docker container create --name <containerName> <baseimage> or docker create --name <containerName> <baseimage> Syntax docker container create --name nginx_base -p 80:80 nginx:alpine docker create --name nginx_base -p 80:80 nginx:alpine
  • 21.
    DOCKER COMMANDS Run theContainer Syntax docker run <flags> <containerName> <shell> Example docker run -dp 80:80 myimage -d = -d flag to run the container in detached mode (background service) -p = -p flag is used to open the port of application
  • 22.
    DOCKER COMMANDS Go insidethe container Syntax docker exec <flag> <containerId> <shell> Example docker exec -it #283aas9878a /bin/bash -i = --interactive or -i flag to indicate that the container’s STDIN should be opened. -t = -t flag to allocate a psuedo-TTY to be able to run interactive commands
  • 23.
    DOCKER COMMANDS Listing AllRunning Containers docker ps
  • 24.
    DOCKER COMMANDS Listing AllStopped or Started Containers docker ps -a
  • 25.
    Copy a filefrom the host to a container Syntax docker cp TARGET CONTAINER:SOURCE Example docker cp index.html web:/index.html
  • 26.
    Copy a filefrom a container to the host Syntax docker cp CONTAINER:SOURCE TARGET Example docker cp web:/index.html index.html
  • 27.
    It's hard tostart with fresh OS images Better to use Technology Specific Images Suppose if you are a Node Js Developer better to start with node image instead of using ubuntu and install node in the image. Will be waste of our time . So we will use docker pull node:latest Suppose you are a Python Developer the your will use docker pull python:latest
  • 28.
    Ports Ports are communicationpath of a operating system (i.e container)
  • 29.
  • 30.
  • 31.
    Build Your OwnImage/Container You can build your own container/image using a “Dockerfile” Syntax docker image build -t ImageName:TagName dir or docker build -t ImageName:TagName dir Example docker build -t myimage:1.0.0 . Docker - File
  • 33.
    Dockerfile Sample (NodeJS) FROMnode WORKDIR /var/www/rtc_app COPY . . RUN npm install EXPOSE 5000 CMD ["node","backend/server.js"]
  • 34.
    Dockerfile Sample (Python) FROMpython:latest WORKDIR /home COPY . . RUN python -m pip install -r requirements.txt EXPOSE 8000 RUN django-admin startproject anil . CMD [ "python","manage.py","runserver","0.0.0.0:8000" ]
  • 35.
    Biggest problem forus now. "I want to work in host OS but wanted to see the changes in running container" The Next Topic "Volume/Mounting" will give this answer
  • 36.
  • 37.
    There are 2Ways 1. Using Command line 2. Using Docker compose file
  • 38.
    Note You can't mounta VOLUME in a Dockerfile specifying both source (host) and destination (container) paths. This is because this idea does not fit the basic concept that Docker image is portable and independent of host.
  • 40.
    How container cantalk to each other ? Application Database
  • 42.
    By default containersare isolated, means all ports are closed, so container can not talk to each other But ….Some way by which container can talk to each other.
  • 43.
    There are 2Ways 1. Expose the port of container, and allow containers to talk to each other with host OS. ( Not Recommended ) 2. Put the containers inside one network. ( Recommended )
  • 44.
  • 45.
    1. Docker composeis a tool which read a docker-compose.yml file. 2. Build the container according to the commands/instructions provided in the file. Docker compose ( Installation not required on windows) Docker compose ( Installation is required on linux )
  • 46.
    YAML: YAML Ain'tMarkup Language
  • 47.
  • 49.
    version: '3.9' services: service1: container_name: node_cont build:. depends_on: - db ports: - '5000:5000' volumes: - .:/app - /app/node_modules db: image: 'postgres:latest' container_name: db_cont ports: - '5432:5432' environment: POSTGRES_PASSWORD: 'mysecretpassword' POSTGRES_USER: 'oklabs'
  • 50.
    DOCKER COMMANDS Push imageto Docker Hub docker login docker tag firstimage YOUR_DOCKERHUB_NAME/firstimage docker push YOUR_DOCKERHUB_NAME/firstimage
  • 51.
    Note:- docker image buildread and build the "Dockerfile" file docker-compose read and build the "docker-compose.yml" file
  • 52.
    docker build Dockerfile docker-composedocker-compose.yml Build Look Build Look Container
  • 53.
    Docker Terminology Docker Image DockerContainer Docker Daemon Docker Registry Docker Client Dockerfile
  • 54.
    Database # DB NameDB Type DB GUI PORT Links 1 MongoDB NoSQL MongoDB Compass 27017 https://www.mongodb.com/try/ download/compass 2 Redis DB NoSQL Redis Insight 6379 https://redis.com/redis-enterpri se/redis-insight/ 3 MySQL SQL Workbench 3306 https://dev.mysql.com/downlo ads/workbench/ 4 PostGres SQL PgAdmin 5432 https://www.pgadmin.org/dow nload/
  • 55.
    Docker Assignment NoSQL DBs Downloadmongo image and implement the nodejs / python code. Download redis image and implement the nodejs/python code. SQL DBs Download mysql image and implement the nodejs / python code. Download postgres image and implement the nodejs / python code.
  • 56.
    Imp Commands docker run--name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3306:3306 -d mysql:tag docker run --name postgres-db -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres
  • 57.
    Remember Stop the databaseservices in Host Machine Solution for windows : 1. Stop docker container 2. win + r and type services.msc 3. Find postgres/mongo services and stop 4. Start your container again
  • 58.
    Notes By default containersare isolated, means all ports are closed. We can open the port in 3 Ways 1. using EXPOSE command in Dockerfile. 2. Using --expose flag in docker run command. 3. Using docker-compose So external service can talk to container and vice versa. docker run = docker pull + docker create + docker start nodemon -L <script_file> docker logs -f <container_name>
  • 59.
    Q & A Howto check which containers are running ? docker ps Write down any 5 Dockerfile commands? Which is the first Dockerfile command ? FROM What is the command to stop all running container ? docker stop $(docker ps -q) What is the command to stop all container ? docker stop $(docker ps -a -q) What is the command to remove all containers ? docker rm $(docker ps -a -q) What is the command to remove the image? docker rmi imagename/imageId
  • 60.
    Useful docker commands dockerstop $(docker ps -a -q) docker rm $(docker ps -a -q) docker-compose up --build -d
  • 61.
    Do you whatto learn Software Development ? I have 10 Yrs of Teaching and Software industry Experience. Your can contact me on whatsApp +91-7999452711 or anildalar8888@gmail.com. I teach my students across the globe. Classes are daily basis Monday to Saturday 2 Hr Daily, Daily Assignment, Daily Quiz, Daily Practice . After the Training you will get Training and Experience Certifications form OKLABS and DOLLORINFOTECH respectively . 100% placement after the training..
  • 62.
  • 63.
    GIT, HTML5,CSS3,BootStrap,JS,JQuery, ReactJS,NodeJS,ExpressJS, MongoDB,MySQL,Redis,PostGres (All Dbs SQL n NoSQL), Docker,NgRok Live Project Deployment Placement IN MNC Certificates 1. OKLABS Training Certificate (1 Year) 1. DOLLOR INFOTECH Experience Certificate (1 Year)
  • 64.
    FullStack 1K USD StudentCan Pay in 3 EMI 333USD x 3 In order to enroll You Must pay 1 EMI All Videos will be Private VIdeos. 1. Daily Class (Monday to Saturday 8:30 AM IST - 9:30 AM IST) 2. Daily Assignment 3. Daily Quiz 4. You will be added into the WhatSAPP Group for Discussion 5. You can Call for Doubts and have anydesk session for discussion