Docker Part1
Class 79th DOCKER INTRO Part1 1st August
Monolithic :Means single application ,server database deployed in single server is called monolithic application
Microservice: We have split the server and service muliple instance for single application
APPLICATION: Collection of services
MONOLITHIC: multiple services are deployed on single server with single database.
MICRO SERVICES: multiple services are deployed on multiple servers with multiple database.
BASED ON USERS AND APP COMPLEXITY WE NEED TO SELECT THE ARCHITECTURE.
FACTORS AFFECTING FOR USING MICROSERVICES:
F-1: COST
F-2: MAINTAINANCE
Micro service we are using containers
CONTAINERS: its free of cost and can create multiple containers.
its same as a server/vm.
it will not have any operating system.
os will be on images.
(SERVER=AMI, CONTAINER=IMAGE)
CONTAINER TOOLS: DOCKER, CONTAINERD, ROCKET, CRI-O, PODMAN,
KATA CONTAINER
DOCKER:
- Its an free & opensource tool.
- it is platform independent.
- used to create, run & deploy applications on containers.
- it is introduced on 2013 by solomenhykes & sebastian phal.
- We used GO language to develop the docker.
- here we write files on YAML.
- before docker user faced lot of problems, but after docker there is no issues with the application.
- Docker will use host resources (cpu, mem, n/w, os).
- Docker can run on any OS but it natively supports Linux distributions.
CONTAINERIZATION/DOCKERIZATION:
Process of packing an application with its dependencies(maps).
ex: PUBG
APP= PUBG & DEPENDECY = MAPS
APP= CAKE & DEPENDECY = KNIFE
Step1: ubuntu apt , if amazon linux yum
ubuntu@ip-10-0-2-61:~$ sudo -i
root@ip-10-0-2-61:~# apt update
root@ip-10-0-2-61:~# apt install docker.io -y
root@ip-10-0-2-61:~# docker --version
Docker version 27.5.1, build 27.5.1-0ubuntu3~24.04.2
Step2: Docker is service you need start ,Active by package default it will start only
root@ip-10-0-2-61:~# systemctl start docker.service
root@ip-10-0-2-61:~# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)
Active: active (running) since Fri 2025-08-08 18:30:59 UTC; 6min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 844 (dockerd)
Tasks: 8
Memory: 101.0M (peak: 102.0M)
CPU: 492ms
CGroup: /system.slice/docker.service
└─844 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Step3: If you want to create container , you need image for that image you need get image from docker hub
No images ,if container run need os , os exist in image , image exists
root@ip-10-0-2-61:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Step4: docker hub, using pull it wil get it from the the docker hub
https://hub.docker.com/search?q=ubuntu
root@ip-10-0-2-61:~# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
32f112e3802c: Already exists
Digest: sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
root@ip-10-0-2-61:~#
root@ip-10-0-2-61:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 65ae7a6f3544 3 weeks ago 78.1MB
Step5: using image creating container ,command docker run ubuntu os , give one name to container give name
Below command create container container1 name
root@ip-10-0-2-61:~# docker run --name container1 ubuntu
Below command for -it mean interactive terminal , it will go to internal container after created
Ip-10-0-2-61 ip address is docker host
92dc1437896a for this inside container
root@ip-10-0-2-61:~# docker run -it --name container1 ubuntu
root@92dc1437896a:/#
Step6: Container also we will do
root@92dc1437896a:/# apt update
root@92dc1437896a:/# apt install nginx
root@92dc1437896a:/# ls
bin bin.usr-is-merged boot
if you want exit from the container give command control + D
Step7: list of containers
root@ip-10-0-2-61:~# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92dc1437896a ubuntu "/bin/bash" 7 minutes ago Exited (0) About a minute ago container1
Step8: Control +D exit from the container, Control +pq running container
COMMANDS:
docker pull ubuntu : pull ubuntu image
docker images : to see list of images
docker run -it --name cont1 ubuntu : to create a container
-it (interactive) - to go inside a container
cat /etc/os-release : to see os flavour
Step9:
root@91c51df69572:/# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.2 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
step10:
root@ip-10-0-2-61:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
movies v1 c6fcfdddf5a7 3 days ago 245MB
root@ip-10-0-2-61:~# docker rmi c6fcfdddf5a7
Error response from daemon: conflict: unable to delete c6fcfdddf5a7 (must be forced) - image is being used by stopped container deff3a8b49f6
root@ip-10-0-2-61:~# docker rmi -f c6fcfdddf5a7
Untagged: movies:v1
Deleted: sha256:c6fcfdddf5a73dad77f764c06db339423e85dd4f86b0a6e70a0f308ecea67200
Deleted: sha256:40ae56197fccc7a31d299cd3e9ddc0f66fdd574b5773dc1df7c886934696312c
Deleted: sha256:4d61e0aa2aa1b2c034371f2b68b212fb7996120cbc8c816c9a712e953fcc7a03
Deleted: sha256:10cacaa9c6716e0559888cc54af4a44beb606a48d0f87cfd81c14c638d8a2d7c
Deleted: sha256:65ae7a6f3544bd2d2b6d19b13bfc64752d776bc92c510f874188bfd404d205a3
root@ip-10-0-2-61:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
root@ip-10-0-2-61:~#
root@ip-10-0-2-61:~# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
32f112e3802c: Already exists
Digest: sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
root@ip-10-0-2-61:~#
root@ip-10-0-2-61:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 65ae7a6f3544 3 weeks ago 78.1MB
root@ip-10-0-2-61:~#
root@ip-10-0-2-61:~# docker pull redhat/granite-3-2b-instruct
Using default tag: latest
latest: Pulling from redhat/granite-3-2b-instruct
40049f9dc504: Pull complete
968eabd7fc8a: Downloading [================> ] 769.4MB/2.28GB
1e37173e4f88: Download complete
context canceled
root@ip-10-0-2-61:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 65ae7a6f3544 3 weeks ago 78.1MB
root@ip-10-0-2-61:~# docker run --name container1 ubuntu
root@ip-10-0-2-61:~# docker run -it --name container1 ubuntu
root@92dc1437896a:/# ^C
root@92dc1437896a:/# apt update
root@92dc1437896a:/# apt install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
iproute2 libatm1t64 libbpf1 libcap2-bin libelf1t64 libmnl0 libpam-cap libxtables12 nginx-common
Suggested packages:
iproute2-doc python3:any fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
iproute2 libatm1t64 libbpf1 libcap2-bin libelf1t64 libmnl0 libpam-cap libxtables12 nginx nginx-common
0 upgraded, 10 newly installed, 0 to remove and 4 not upgraded.
Need to get 2025 kB of archives.
After this operation, 5799 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Abort.
root@92dc1437896a:/#
root@92dc1437896a:/#
root@92dc1437896a:/# apt install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
iproute2 libatm1t64 libbpf1 libcap2-bin libelf1t64 libmnl0 libpam-cap libxtables12 nginx-common
Suggested packages:
iproute2-doc python3:any fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
iproute2 libatm1t64 libbpf1 libcap2-bin libelf1t64 libmnl0 libpam-cap libxtables12 nginx nginx-common
0 upgraded, 10 newly installed, 0 to remove and 4 not upgraded.
Need to get 2025 kB of archives.
After this operation, 5799 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
root@92dc1437896a:/# ls
bin bin.usr-is-merged boot dev etc home lib lib64 media mnt opt proc root run sbin sbin.usr-is-merged srv sys tmp usr var
root@92dc1437896a:/#
exit
root@ip-10-0-2-61:~# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92dc1437896a ubuntu "/bin/bash" 7 minutes ago Exited (0) About a minute ago container1
deff3a8b49f6 c6fcfdddf5a7 "/usr/sbin/apachectl…" 3 days ago Exited (0) 3 days ago cont1
root@ip-10-0-2-61:~# docker container ls -pq
unknown shorthand flag: 'p' in -pq
See 'docker container ls --help'.
root@ip-10-0-2-61:~# docker container ls -p
unknown shorthand flag: 'p' in -p
See 'docker container ls --help'.
root@ip-10-0-2-61:~# docker run -it --name container1 ubuntu
docker: Error response from daemon: Conflict. The container name "/container1" is already in use by container "92dc1437896aa0ebba784e987052c682ada5c66229501195529b4422bce505fd". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
root@ip-10-0-2-61:~# docker run --name container1 ubuntu
docker: Error response from daemon: Conflict. The container name "/container1" is already in use by container "92dc1437896aa0ebba784e987052c682ada5c66229501195529b4422bce505fd". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
root@ip-10-0-2-61:~# docker run ubuntu
root@ip-10-0-2-61:~# docker run -it --name container1 ubuntu
docker: Error response from daemon: Conflict. The container name "/container1" is already in use by container "92dc1437896aa0ebba784e987052c682ada5c66229501195529b4422bce505fd". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
root@ip-10-0-2-61:~# docker run -it --name container1
"docker run" requires at least 1 argument.
See 'docker run --help'.
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Step 11: after inside container control p+q, container is up and running not exist
Control+d exit from the contrainer
Create and run a new container from an image
root@ip-10-0-2-61:~# docker run -it --name container2 ubuntu
root@91c51df69572:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@91c51df69572:/# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.2 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
root@91c51df69572:/# root@ip-10-0-2-61:~#
root@ip-10-0-2-61:~# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91c51df69572 ubuntu "/bin/bash" 2 minutes ago Up 2 minutes container2
c7863af60d25 ubuntu "/bin/bash" 3 minutes ago Exited (0) 2 minutes ago blissful_bose
92dc1437896a ubuntu "/bin/bash" 15 minutes ago Exited (0) 10 minutes ago container1
deff3a8b49f6 c6fcfdddf5a7 "/usr/sbin/apachectl…" 3 days ago Exited (0) 3 days ago cont1
root@ip-10-0-2-61:~#
Step 12 :Start the container manually using below command
root@ip-10-0-2-61:~# docker start container1
container1
root@ip-10-0-2-61:~# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91c51df69572 ubuntu "/bin/bash" 8 minutes ago Up 8 minutes container2
c7863af60d25 ubuntu "/bin/bash" 9 minutes ago Exited (0) 9 minutes ago blissful_bose
92dc1437896a ubuntu "/bin/bash" 22 minutes ago Up 30 seconds container1
Stop
root@ip-10-0-2-61:~# docker stop container1
container1
root@ip-10-0-2-61:~# docker kill container1
container1
ps also same docker container -a
root@ip-10-0-2-61:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91c51df69572 ubuntu "/bin/bash" 12 minutes ago Up 12 minutes container2
c7863af60d25 ubuntu "/bin/bash" 13 minutes ago Exited (0) 13 minutes ago blissful_bose
92dc1437896a ubuntu "/bin/bash" 26 minutes ago Up 23 seconds container1
root@ip-10-0-2-61:~# docker pause container1
container1
root@ip-10-0-2-61:~# docker unpause container1
container1
Step12: inspect gives you complete information of the container
root@ip-10-0-2-61:~# docker inspect container1
[
{
"Id": "92dc1437896aa0ebba784e987052c682ada5c66229501195529b4422bce505fd",
"Created": "2025-08-08T19:13:18.076228102Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
Step13: you want remove the container, you need to kill or stop the container
root@ip-10-0-2-61:~# docker stop container1
container1
root@ip-10-0-2-61:~# docker rm container1
container1
root@ip-10-0-2-61:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91c51df69572 ubuntu "/bin/bash" 17 minutes ago Up 17 minutes container2
--Thanks