Tuesday, August 5, 2025

Docker part 4

Docker part 4

High Availability: more than one server

why: if one server got deleted then other server will gives the app

(docker swarm one container copy multiple servers manage the worker node)
DOCKER SWARM:
  • its an orchestration tool for containers. 
  • used to manage multiple containers on multiple servers.
  • here we create a cluster (group of servers).
  • in that cluster, we can create same container on multiple servers.
  • here we have the manager node and worker node.
  • manager node will create & distribute the container to worker nodes.
  • worker node's main purpose is to maintain the container.
  • without docker engine we cant create the cluster.
  • Port: 2377
  • worker node will join on cluster by using a token.
  • manager node will give the token.
manager node  we have create container ,it will distribute worker nodes, worker node to connect token required ,all worker node open the port 2377 then only it will work

Step1: We have create three servers, all servers need to install docker 

Step2: Docker installation

root@dockerhost:~/docker#apt install docker.io -y
root@dockerhost:~/docker# docker --version
Docker version 27.5.1, build 27.5.1-0ubuntu3~24.04.2

Worker1:
root@ip-10-0-2-60:~# docker --version
Docker version 27.5.1, build 27.5.1-0ubuntu3~24.04.2
Worker2:
root@ip-10-0-2-62:~# docker --version
Docker version 27.5.1, build 27.5.1-0ubuntu3~24.04.2

Step2: in manger server run the command Docker swarm , get the token copy the token to all worker node ,it will manage all worker nodes 

root@dockerhost:~/docker# docker swarm init
Swarm initialized: current node (8jt0pszkvuxlj24a0aatlmz8o) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-1b6ovsg5p0s5ceudu18596rj1yrcy3q82xeiilgovwwytzleiz-4x0nxqdzrp2yvzqv02qokiaba 10.0.2.61:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

Worker node1 :

root@ip-10-0-2-60:~# docker swarm join --token SWMTKN-1-1b6ovsg5p0s5ceudu18596rj1yrcy3q82xeiilgovwwytzleiz-4x0nxqdzrp2yvzqv02qokiaba 10.0.2.61:2377
This node joined a swarm as a worker.

Worker node2 :

root@ip-10-0-2-62:~# docker swarm join --token SWMTKN-1-1b6ovsg5p0s5ceudu18596rj1yrcy3q82xeiilgovwwytzleiz-4x0nxqdzrp2yvzqv02qokiaba 10.0.2.61:2377
This node joined a swarm as a worker.

After added token in workernode ,automatically active the worker node in manager node 

root@dockerhost:~/docker# docker node ls
ID                            HOSTNAME       STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
8jt0pszkvuxlj24a0aatlmz8o *   dockerhost     Ready     Active         Leader           27.5.1
gpmbxxqougicd8i0aob627ykf     ip-10-0-2-60   Ready     Active                          27.5.1
8flw0oqw6xjzw9ot8y612s8k3     ip-10-0-2-62   Ready     Active                          27.5.1

Step3:

root@dockerhost:~/docker# docker run -itd --name container1 -p 81:80 vakatisubbu/movies:latest
0388dee24ec4b6533b9a533f2c0c8bae13e3d4cee33122e90e5f3d6ccef2da9b



Step4: when every create container in manage server automatically worker node created container
for that you need create first service 

Note: individual containers are not going to replicate.
if we create a service then only containers will be distributed.

SERVICE: it's a way of exposing and managing multiple containers.
in service we can create copy of conatiners.
that container copies will be distributed to all the nodes.

service -- > containers -- > distributed to nodes

step5: remove the existing container 
root@dockerhost:~/docker# docker rm  0388dee24ec4
0388dee24ec4
root@dockerhost:~/docker# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Step6: Create service 

root@dockerhost:~/docker# docker service create --name movies --replicas 3 -p 81:80 vakatisubbu/movies:latest
zrs0y900dk4pf2cptavq7jv1m
overall progress: 3 out of 3 tasks
1/3: running   [==================================================>]
2/3: running   [==================================================>]
3/3: running   [==================================================>]
verify: Service zrs0y900dk4pf2cptavq7jv1m converged

Automatically came to all worker nodes 
Worker node 1
root@ip-10-0-2-60:~# docker ps -a
CONTAINER ID   IMAGE                       COMMAND                  CREATED          STATUS          PORTS     NAMES
9ddfec38443f   vakatisubbu/movies:latest   "/usr/sbin/apachectl…"   25 seconds ago   Up 24 seconds             movies.1.zrt2pageb1yawgsu3ikd54q21

Worker node 2
root@ip-10-0-2-62:~# docker ps -a
CONTAINER ID   IMAGE                       COMMAND                  CREATED          STATUS          PORTS     NAMES
882a20decb78   vakatisubbu/movies:latest   "/usr/sbin/apachectl…"   54 seconds ago   Up 53 seconds             movies.2.n3se13cdty5jjtvt8dsw4s1xl

Step6:See now same application running all servers this is called high availability



Step7: docker service commands , it will work in manager node only 

root@dockerhost:~/docker# docker service ls
ID             NAME               MODE         REPLICAS   IMAGE                       PORTS
vis3a3ilm480   gracious_taussig   replicated   0/1        movies:latest
zrs0y900dk4p   movies             replicated   3/3        vakatisubbu/movies:latest   *:81->80/tcp

root@dockerhost:~/docker# docker service inspect movies


root@dockerhost:~/docker# docker service ps  movies
ID             NAME       IMAGE                       NODE           DESIRED STATE   CURRENT STATE           ERROR     PORTS
zrt2pageb1ya   movies.1   vakatisubbu/movies:latest   ip-10-0-2-60   Running         Running 6 minutes ago
n3se13cdty5j   movies.2   vakatisubbu/movies:latest   ip-10-0-2-62   Running         Running 6 minutes ago
t3z17nhvws8c   movies.3   vakatisubbu/movies:latest   dockerhost     Running         Running 6 minutes ago

 For practice :

docker service scale movies=10 : to scale in the containers
docker service scale movies=3 : to scale out the containers
docker service rollback movies : to go previous state
docker service logs movies : to see the logs

If you are remove service automatically container removed in worker nodes also 
docker service rm movies : to delete the services.


Step8:

Manager node :

root@dockerhost:~/docker# docker service create --name movies --replicas 3 -p 81:80 vakatisubbu/movies:latest
khzwkp7bezihktyo844qe7gmo
overall progress: 3 out of 3 tasks
1/3: running   [==================================================>]
2/3: running   [==================================================>]
3/3: running   [==================================================>]
verify: Service khzwkp7bezihktyo844qe7gmo converged

Step9: swarm is self healing , we will try to kill container in worker2 

root@ip-10-0-2-62:~# docker ps -a
CONTAINER ID   IMAGE                       COMMAND                  CREATED              STATUS              PORTS     NAMES
62928f113c25   vakatisubbu/movies:latest   "/usr/sbin/apachectl…"   About a minute ago   Up About a minute             movies.3.9pr1bum3hjrfw9dpot3m5yq1k
root@ip-10-0-2-62:~# docker kill 62928f113c25
62928f113c25
root@ip-10-0-2-62:~# docker ps -a
CONTAINER ID   IMAGE                       COMMAND                  CREATED         STATUS                       PORTS     NAMES
6c2a01a5299e   vakatisubbu/movies:latest   "/usr/sbin/apachectl…"   5 seconds ago   Created                                movies.3.gszek2kff5ln97tbpsgr0la2m
62928f113c25   vakatisubbu/movies:latest   "/usr/sbin/apachectl…"   2 minutes ago   Exited (137) 5 seconds ago             movies.3.9pr1bum3hjrfw9dpot3m5yq1k

Step10: but application still working 

Step11: if kill also automatically immediately ,manager create new container .that is self healing 



But We will use Kubernates , realtime not using much 

Step12: commands for docker service 

root@dockerhost:~# docker service ls
ID             NAME      MODE         REPLICAS   IMAGE                       PORTS
khzwkp7bezih   movies    replicated   3/3        vakatisubbu/movies:latest   *:81->80/tcp

Node all work node information 

root@dockerhost:~# docker node ls
ID                            HOSTNAME       STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
8jt0pszkvuxlj24a0aatlmz8o *   dockerhost     Ready     Active         Leader           27.5.1
gpmbxxqougicd8i0aob627ykf     ip-10-0-2-60   Ready     Active                          27.5.1
8flw0oqw6xjzw9ot8y612s8k3     ip-10-0-2-62   Ready     Active                          27.5.1

Particular node informration

root@dockerhost:~# docker inspect gpmbxxqougicd8i0aob627ykf
[
    {
        "ID": "gpmbxxqougicd8i0aob627ykf",
        "Version": {


Step13: Need to remove node , first need down the worker node 

worker1 you need entry this command 
root@ip-10-0-2-60:~# docker swarm leave
Node left the swarm.

Manager need check the status of nodes ,See now down 

root@dockerhost:~# docker node ls
ID                            HOSTNAME       STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
8jt0pszkvuxlj24a0aatlmz8o *   dockerhost     Ready     Active         Leader           27.5.1
gpmbxxqougicd8i0aob627ykf     ip-10-0-2-60   Down      Active                          27.5.1
8flw0oqw6xjzw9ot8y612s8k3     ip-10-0-2-62   Ready     Active                          27.5.1


After down you using rm command remove the node 

root@dockerhost:~# docker node rm gpmbxxqougicd8i0aob627ykf
gpmbxxqougicd8i0aob627ykf

Run 'docker node COMMAND --help' for more information on a command.
root@dockerhost:~# docker node ls
ID                            HOSTNAME       STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
8jt0pszkvuxlj24a0aatlmz8o *   dockerhost     Ready     Active         Leader           27.5.1
8flw0oqw6xjzw9ot8y612s8k3     ip-10-0-2-62   Ready     Active                          27.5.1

Step14: if want re add the node , just enter the command join token again in worknode,it will add automatically 

Worker node 
root@ip-10-0-2-60:~# docker swarm join --token SWMTKN-1-1b6ovsg5p0s5ceudu18596rj1yrcy3q82xeiilgovwwytzleiz-4x0nxqdzrp2yvzqv02qokiaba 10.0.2.61:2377
This node joined a swarm as a worker.

Manager node see readded
root@dockerhost:~# docker node ls
ID                            HOSTNAME       STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
8jt0pszkvuxlj24a0aatlmz8o *   dockerhost     Ready     Active         Leader           27.5.1
fbpsc3hjqsh3sntv9g17c88jq     ip-10-0-2-60   Ready     Active                          27.5.1
8flw0oqw6xjzw9ot8y612s8k3     ip-10-0-2-62   Ready     Active                          27.5.1

Purpose: Communicating two servers ,now not using kubertes
there is no autoscaling,load balancing not exist in docker swarm


                                        DOCKER NETWORKING:
Docker networks are used to make communication between the multiple containers that are running on same or different docker hosts. 

We have different types of docker networks.
Bridge Network : SAME HOST
Overlay network : DIFFERENT HOST
Host Network
None network

 
BRIDGE NETWORK: It is a default network that container will communicate with each other within the same host.(Two container communicating each other we use Bridge network same host)

OVERLAY NETWORK: Used to communicate containers with each other across the multiple docker hosts. (Two host servers ,communicate two different containers overlaynetwork)

HOST NETWORK: When you Want your container IP and ec2 instance IP same then you use host network

NONE NETWORK: When you don’t Want The container to get exposed to the world, we use none network. It will not provide any network to our container.


root@dockerhost:~# docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
38a9eb42edc7   bridge            bridge    local
bc0d91e098f7   docker_gwbridge   bridge    local
8797cf25d831   host              host      local
5fj7zbvzq7ft   ingress           overlay   swarm
7fbb54dd8455   none              null      local
root@dockerhost:~#

Step1: Creating customize network 

root@dockerhost:~# docker network create vakatisubbu
fefe5c82ecc3952a05fcf2795d4cc9218b206dcdd27531a7338a851c08dfbeaf

See her vakatisubbu own network create 
root@dockerhost:~# docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
38a9eb42edc7   bridge            bridge    local
bc0d91e098f7   docker_gwbridge   bridge    local
8797cf25d831   host              host      local
5fj7zbvzq7ft   ingress           overlay   swarm
7fbb54dd8455   none              null      local
fefe5c82ecc3   vakatisubbu       bridge    local

Details about network type , if any  network default network type coming as bridge

root@dockerhost:~# docker service inspect vakatisubbu
[]
Status: Error: no such service: vakatisubbu, Code: 1
root@dockerhost:~# docker network  inspect vakatisubbu    


Step1: To change the bridge network default to custom network

Sample created one container 
root@dockerhost:~# docker run -itd --name container1 ubuntu
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
32f112e3802c: Already exists
Digest: sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
Status: Downloaded newer image for ubuntu:latest
13f93d4dd337b5dff463281118fff525fab8202e76361ab1725c97fac85ab4ea


root@dockerhost:~# docker ps -a
CONTAINER ID   IMAGE                       COMMAND                  CREATED          STATUS          PORTS     NAMES
13f93d4dd337   ubuntu                      "/bin/bash"              7 seconds ago    Up 6 seconds              container1
2767ee65764a   vakatisubbu/movies:latest   "/usr/sbin/apachectl…"   45 minutes ago   Up 44 minutes             movies.1.ddh2ltx74sct0zogr23dk3vdf
root@dockerhost:~# docker run -itd --name container2 ubuntu
6ecfa2faaef621a7e857b600fef7a34063bdf73e0ab5c4916d2a1a448c795b2a
root@dockerhost:~# docker ps -a
CONTAINER ID   IMAGE                       COMMAND                  CREATED              STATUS          PORTS     NAMES
6ecfa2faaef6   ubuntu                      "/bin/bash"              4 seconds ago        Up 3 seconds              container2
13f93d4dd337   ubuntu                      "/bin/bash"              About a minute ago   Up 59 seconds             container1
2767ee65764a   vakatisubbu/movies:latest   "/usr/sbin/apachectl…"   45 minutes ago       Up 45 minutes             movies.1.ddh2ltx74sct0zogr23dk3vdf


Step2:  
See by  default network type Bridge, adding this into vakatisubbu bridge

root@dockerhost:~# docker inspect 6ecfa2faaef6
"NetworkSettings": {
            "Bridge": "",
            "SandboxID": "4dda7e27fff8832bdfc3700dc2d0ab388e90a3b136d7ba1869470e791eeb4dcc",
            "SandboxKey": "/var/run/docker/netns/4dda7e27fff8",
            "Ports": {},

root@dockerhost:~# docker network connect vakatisubbu container1

See now container added to network 
root@dockerhost:~# docker network inspect  vakatisubbu

  "ConfigOnly": false,
        "Containers": {
            "13f93d4dd337b5dff463281118fff525fab8202e76361ab1725c97fac85ab4ea": {
                "Name": "container1",
                "EndpointID": "75fcb0f196865f7b9de577c9dff039777f9b829f802c0fbe71fc04bd57f2c242",
                "MacAddress": "02:42:ac:13:00:02",
                "IPv4Address": "172.19.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

Step3: Now two container in same network
root@dockerhost:~# docker network connect vakatisubbu container2
root@dockerhost:~# docker network inspect  vakatisubbu
   "ConfigOnly": false,
        "Containers": {
            "13f93d4dd337b5dff463281118fff525fab8202e76361ab1725c97fac85ab4ea": {
                "Name": "container1",
                "EndpointID": "75fcb0f196865f7b9de577c9dff039777f9b829f802c0fbe71fc04bd57f2c242",
                "MacAddress": "02:42:ac:13:00:02",
                "IPv4Address": "172.19.0.2/16",
                "IPv6Address": ""
            },
            "6ecfa2faaef621a7e857b600fef7a34063bdf73e0ab5c4916d2a1a448c795b2a": {
                "Name": "container2",
                "EndpointID": "18ad6846b64edeb8ae78b5943a18a2f48de7886e41331118f314cdbdfd878e2d",
                "MacAddress": "02:42:ac:13:00:03",
                "IPv4Address": "172.19.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

Step4: Jenkins installation in docker , software get form the docker register hub 

INSTALLING MULTIPLE TOOLS 

docker run -it --name jenkins -p 8080:8080 jenkins/jenkins:lts
docker run -it --name prometheus-container -e TZ=UTC -p 9090:9090 prom/prometheus
docker run -d --name grafana -p 3000:3000 grafana/grafana



Below is the Docker architecture :
We have three component docker client ,docker host and docker registry 
docker client(docker pull,docker push...), we will ask image client , if image not exist ,it will ask host ,if host not exist it will get the registry for the image os 

Daemon is control all containers ,services and images






DATABASE SETUP 

docker run -itd --name dbcont -e MYSQL_ROOT_PASSWORD=test123 mysql:8.0
docker exec -it dbcont bash
mysql -u root -p

--Database installed successfully.

bash-5.1# mysql --version
mysql  Ver 8.0.43 for Linux on x86_64 (MySQL Community Server - GPL)


--Thanks 



Monday, August 4, 2025

Docker part3

Docker

Class 81st AWS Docker part 3 August 4th 

Docker Compose

Docker hub

Step1: Launched one Ec2 ubuntu server 

ubuntu@ip-10-0-2-61:~$ sudo -i

root@ip-10-0-2-61:~#

root@ip-10-0-2-61:~# apt install docker.io -y

Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /usr/lib/systemd/system/containerd.service.
Setting up ubuntu-fan (0.12.16+24.04.1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/ubuntu-fan.service → /usr/lib/systemd/system/ubuntu-fan.service.
Setting up docker.io (27.5.1-0ubuntu3~24.04.2) ...
info: Selecting GID from range 100 to 999 ...
info: Adding group `docker' (GID 113) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /usr/lib/systemd/system/docker.socket.
Processing triggers for dbus (1.14.10-4ubuntu4.1) ...
Processing triggers for man-db (2.12.0-4build2) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

--For our understand created on directory
root@ip-10-0-2-61:~# mkdir docker

--In ubuntu if you installed any package service will be automatically start, see below status of the Docker is active started, because at the time of installation time only it will create link

root@ip-10-0-2-61:~/docker# 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 Tue 2025-08-05 15:06:02 UTC; 1min 52s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 1910 (dockerd)
      Tasks: 8
     Memory: 27.1M (peak: 27.3M)
        CPU: 319ms
     CGroup: /system.slice/docker.service
             └─1910 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Aug 05 15:06:00 ip-10-0-2-61 systemd[1]: Starting docker.service - Docker Application Container Engine...
Aug 05 15:06:00 ip-10-0-2-61 dockerd[1910]: time="2025-08-05T15:06:00.784849975Z" level=info msg="Starting up"
Aug 05 15:06:00 ip-10-0-2-61 dockerd[1910]: time="2025-08-05T15:06:00.786203084Z" level=info msg="OTEL tracing is not configured, using no-op trace>
Aug 05 15:06:00 ip-10-0-2-61 dockerd[1910]: time="2025-08-05T15:06:00.786521956Z" level=info msg="detected 127.0.0.53 nameserver, assuming systemd->
Aug 05 15:06:01 ip-10-0-2-61 dockerd[1910]: time="2025-08-05T15:06:01.675399870Z" level=info msg="Loading containers: start."
Aug 05 15:06:02 ip-10-0-2-61 dockerd[1910]: time="2025-08-05T15:06:02.274854781Z" level=info msg="Loading containers: done."
Aug 05 15:06:02 ip-10-0-2-61 dockerd[1910]: time="2025-08-05T15:06:02.363019274Z" level=info msg="Docker daemon" commit="27.5.1-0ubuntu3~24.04.2" c>
Aug 05 15:06:02 ip-10-0-2-61 dockerd[1910]: time="2025-08-05T15:06:02.363143457Z" level=info msg="Daemon has completed initialization"
Aug 05 15:06:02 ip-10-0-2-61 dockerd[1910]: time="2025-08-05T15:06:02.413772835Z" level=info msg="API listen on /run/docker.sock"
Aug 05 15:06:02 ip-10-0-2-61 systemd[1]: Started docker.service - Docker Application Container Engine

Step2:docker file need to create , need to deploy the file into frontend 

see below apt installation,cmd control the apache

root@ip-10-0-2-61:~/docker# vi Dockerfile

root@dockerhost:~/docker# cat Dockerfile

FROM ubuntu

RUN apt update -y

RUN apt install apache2 -y

COPY index.html /var/www/html

CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]


Step3: Create index.html 
https://www.w3schools.com/howto/howto_css_login_form.asp

I have click the Form with icons,click Try your self register text change to Paytm movies

root@ip-10-0-2-61:~/docker# vi index.html 
copy the above save 

Image Build :

root@ip-10-0-2-61:~/docker# docker  build -t movies:v1 .

Successfully built 005ec395606c

Successfully tagged movies:v1

Creating Container 

Step4: d indict it will not go inside the container after creation, it will come out from  the container

root@dockerhost:~/docker# docker run -itd --name container1 -p 81:80 movies:v1
24c8d09e68c4055661823f3c6617e40e32d1707fcb403765ab96b2338307afa6

Step5: Paytm movie working like that why you can create ,multiple page 
1)Paytm Movies 
2)Train
3)Recharge 

1)Movies
2)Train Create 
root@dockerhost:~/docker# docker run -itd --name container1 -p 81:80 movies:v1
root@dockerhost:~/docker# docker run -itd --name container2 -p 82:80 train:v1


3)Recharge


Note: In the above process all the containers are managed and created one by one in real time we manage all the containers at same time so for that purpose we are going to use the concept called Docker compose.


DOCKER COMPOSE:
  • It's a tool used to manage multiple containers in single host.
  • we can create, start, stop, and delete all containers together.
  • we write container information in a file called a compose file.
  • compose file is in YAML format.
  • inside the compose file we can give images, ports, and volumes info of containers.
  • we need to download this tool and use it. (AMAZON LINUX)

Ubuntu not exist compose
root@dockerhost:~/docker# docker-compose
Command 'docker-compose' not found, but can be installed with:
snap install docker          # version 28.1.1+1, or
apt  install docker-compose  # version 1.29.2-6
See 'snap info docker' for additional versions.

Step1: installation

https://docs.docker.com/engine/install/ubuntu/

INSTALLATION:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose version

root@dockerhost:~/docker# docker-compose --version
docker-compose version 1.29.1, build c34c88b2


Step2:

CHANGING THE DEFULT FILE:

by default the docker-compose wil support the following names
docker-compose.yml, docker-compose.yaml, compose.yml, compose.yaml

mv docker-compose.yml raham.yml
docker-compose up -d : throws an error

docker-compose -f raham.yml up -d
docker-compose -f raham.yml ps
docker-compose -f raham.yml down

root@dockerhost:~/docker# vi compose.yaml
root@dockerhost:~/docker# cat compose.yaml
version: '3.8'
services:
  movies:
    image: movies:v1
    ports:
      - "81:80"
  train:
    image: train:v1
    ports:
      - "82:80"
  recharge:
    image: recharge:v1
    ports:
      - "83:80"


Step3: kill the container which is running existing port 

root@dockerhost:~/docker# docker kill $(docker ps -aq)
root@dockerhost:~/docker# docker ps -a
root@dockerhost:~/docker# docker rm $(docker ps -aq)
root@dockerhost:~/docker# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

root@dockerhost:~/docker# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
recharge     v1        b2a586051a66   26 minutes ago   245MB
train        v1        a26258ccbab4   30 minutes ago   245MB
movies       v1        1b7a6480b8ac   35 minutes ago   245MB

Step4: Automatically 3 container created automatically 

root@dockerhost:~/docker# docker-compose up -d
Creating network "docker_default" with the default driver
Creating docker_movies_1   ... done
Creating docker_train_1    ... done
Creating docker_recharge_1 ... done

Step5: list of docker-compose ps 

root@dockerhost:~/docker# docker-compose ps -a
      Name                     Command               State                Ports
---------------------------------------------------------------------------------------------
docker_movies_1     /usr/sbin/apachectl -D FOR ...   Up      0.0.0.0:81->80/tcp,:::81->80/tcp
docker_recharge_1   /usr/sbin/apachectl -D FOR ...   Up      0.0.0.0:83->80/tcp,:::83->80/tcp
docker_train_1      /usr/sbin/apachectl -D FOR ...   Up      0.0.0.0:82->80/tcp,:::82->80/tcp

root@dockerhost:~/docker# docker-compose images
    Container       Repository   Tag     Image Id       Size
--------------------------------------------------------------
docker_movies_1     movies       v1    1b7a6480b8ac   244.6 MB
docker_recharge_1   recharge     v1    b2a586051a66   244.6 MB
docker_train_1      train        v1    a26258ccbab4   244.6 MB

Step6:  Stop 
root@dockerhost:~/docker# docker-compose stop
Stopping docker_recharge_1 ... done
Stopping docker_train_1    ... done
Stopping docker_movies_1   ... done
Step7: start
root@dockerhost:~/docker# docker-compose start
Starting movies   ... done
Starting train    ... done
Starting recharge ... done

it will manage all container using docker-compose 

Step7:Logs
root@dockerhost:~/docker# docker-compose logs

Step8: All pages open, but we have maintained all container in one compose fie
Remove 

root@dockerhost:~/docker# docker-compose stop
Stopping docker_recharge_1 ... done
Stopping docker_train_1    ... done
Stopping docker_movies_1   ... done
root@dockerhost:~/docker# docker-compose rm
Going to remove docker_recharge_1, docker_train_1, docker_movies_1
Are you sure? [yN] y
Removing docker_recharge_1 ... done
Removing docker_train_1    ... done
Removing docker_movies_1   ... done

Step9: docker-compose down stop and remove

root@dockerhost:~/docker# docker-compose down
Stopping docker_movies_1   ... done
Stopping docker_recharge_1 ... done
Stopping docker_train_1    ... done
Removing docker_movies_1   ... done
Removing docker_recharge_1 ... done
Removing docker_train_1    ... done
Removing network docker_default

                                            Docker Hub
Docker image we make public use ,put the images in docker hub 
Step1:
https://app.docker.com/accounts/vsmoracle




Step2: docker tag the server using below command 

root@dockerhost:~/docker# docker login

USING WEB-BASED LOGIN
To sign in with credentials on the command line, use 'docker login -u <username>'

Your one-time device confirmation code is: MHHN-FRJM
Press ENTER to open your browser or submit your device code here: https://login.docker.com/activate

Waiting for authentication in the browser…

 
Login url and give active code MHHN-FRJM click confirm 

root@dockerhost:~/docker# docker login
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credential-stores

Login Succeeded
root@dockerhost:~/docker# docker push vakatisubbu/movies




Step3: create one more repository in docker hub 

vakatisubbu/train


root@dockerhost:~/docker# docker tag train:v1 vakatisubbu/train
root@dockerhost:~/docker# docker push vakatisubbu/train
Using default tag: latest
The push refers to repository [docker.io/vakatisubbu/train]
6d62776b1864: Mounted from vakatisubbu/train
54408b735120: Mounted from vakatisubbu/train
70ade84ed73d: Mounted from vakatisubbu/train
107cbdaeec04: Mounted from vakatisubbu/train
latest: digest: sha256:123f7b15cb5977b0909453335b6ce64ede13f709960938021d1edc6d25b5db6d size: 1161

uploaded images successfully in docker hub 

Step4:
root@dockerhost:~/docker# docker tag recharge:v1 vakatisubbu/recharge
root@dockerhost:~/docker# docker push vakatisubbu/recharge

uploaded images successfully in docker hub 


Step5:
root@dockerhost:~/docker# docker rmi -f $(docker images -q)

deleted  all docker imags

Step7: now not images in server, we have docker hub all images 
root@dockerhost:~/docker# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

Step8: docker pull



root@dockerhost:~/docker# docker pull vakatisubbu/movies:latest
latest: Pulling from vakatisubbu/movies
e87500e69896: Downloading [>                                                  ]  306.6kB/30.59MB
e87500e69896: Pull complete
b085d7aa1527: Pull complete
781519f627b4: Pull complete
418464f70534: Pull complete
Digest: sha256:123f7b15cb5977b0909453335b6ce64ede13f709960938021d1edc6d25b5db6d
Status: Downloaded newer image for vakatisubbu/movies:latest
docker.io/vakatisubbu/movies:latest
root@dockerhost:~/docker#
root@dockerhost:~/docker# docker images
REPOSITORY           TAG       IMAGE ID       CREATED       SIZE
vakatisubbu/movies   latest    1b7a6480b8ac   2 hours ago   245MB


root@dockerhost:~/docker# docker pull vakatisubbu/train:latest
latest: Pulling from vakatisubbu/train
e87500e69896: Already exists
b085d7aa1527: Already exists
781519f627b4: Already exists
291db30c8aef: Pull complete
Digest: sha256:b057183d4648d21cd55602d4cc697f1454fcda1713ae2e6ae7e0b279e2771365
Status: Downloaded newer image for vakatisubbu/train:latest
docker.io/vakatisubbu/train:latest
root@dockerhost:~/docker# docker images
REPOSITORY           TAG       IMAGE ID       CREATED       SIZE
vakatisubbu/train    latest    a26258ccbab4   2 hours ago   245MB
vakatisubbu/movies   latest    1b7a6480b8ac   2 hours ago   245MB
root@dockerhost:~/docker# docker pull vakatisubbu/recharge:latest
latest: Pulling from vakatisubbu/recharge
e87500e69896: Already exists
b085d7aa1527: Already exists
781519f627b4: Already exists
f4834f3a85b1: Pull complete
Digest: sha256:0eaad3052ebd2cb36dcfab43349b67fbca558e795673d3c5d463e09f37b218d6
Status: Downloaded newer image for vakatisubbu/recharge:latest
docker.io/vakatisubbu/recharge:latest
root@dockerhost:~/docker# docker images
REPOSITORY             TAG       IMAGE ID       CREATED       SIZE
vakatisubbu/recharge   latest    b2a586051a66   2 hours ago   245MB
vakatisubbu/train      latest    a26258ccbab4   2 hours ago   245MB
vakatisubbu/movies     latest    1b7a6480b8ac   2 hours ago   245MB




--Thanks 

Saturday, August 2, 2025

Docker Part2

Docker Part2

Class 80th DOCKER Part2 August 2nd

What is Containerization 

Creating Container 

Step1:

root@ip-10-0-2-61:~# hostnamectl set-hostname dockerhost

root@ip-10-0-2-61:~# sudo -i

--Remove if already exist 

root@dockerhost:~# docker rm container1
container1
--Create new container -it going inside the container1
root@dockerhost:~# docker run -it --name container1  ubuntu
root@adc881f1c093:/#

Install the application packages in the container 
--apt update in container
root@adc881f1c093:/# apt update
-- Tomcat apache installed in container 

root@adc881f1c093:/# apt install apache2 -y
root@adc881f1c093:/# apache2 -v
Server version: Apache/2.4.58 (Ubuntu)
Server built:   2025-07-14T16:22:22

--Tree install 
root@adc881f1c093:/# apt install tree -y

Creating Some files 1 to 5 
root@adc881f1c093:/# touch file{1..5}
-rw-r--r--   1 root root    0 Aug 10 18:23 file5
-rw-r--r--   1 root root    0 Aug 10 18:23 file4
-rw-r--r--   1 root root    0 Aug 10 18:23 file3
-rw-r--r--   1 root root    0 Aug 10 18:23 file2
-rw-r--r--   1 root root    0 Aug 10 18:23 file1

root@adc881f1c093:/# cat >file1
This is my container1 file1
Step2:

 Custom Image Container backup 
We  have only one image
root@dockerhost:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       latest    65ae7a6f3544   3 weeks ago   78.1MB
We have only one Container
root@dockerhost:~# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                      PORTS     NAMES
adc881f1c093   ubuntu    "/bin/bash"   12 minutes ago   Up 12 minutes                         container1
Docker commit
Step3: Create new image using container1( container1 has all package information)

root@dockerhost:~# docker commit container1 ubuntupkh_img:v1
sha256:327dee052d80405da2565ef6e042f8e2be3eb5226af23af4217408c8b0d57921

root@dockerhost:~# docker images
REPOSITORY      TAG       IMAGE ID       CREATED          SIZE
ubuntupkh_img   v1        327dee052d80   43 seconds ago   245MB
ubuntu          latest    65ae7a6f3544   3 weeks ago      78.1MB

Using New image creating new containers 
Step4: see here automatically came on packages and files information in container2 

root@dockerhost:~# docker run -it --name container2 ubuntupkh_img:v1
root@b95d921f2476:/# ls -lrt
dr-xr-xr-x  13 root root    0 Aug 10 18:22 sys
-rw-r--r--   1 root root    0 Aug 10 18:23 file5
-rw-r--r--   1 root root    0 Aug 10 18:23 file4
-rw-r--r--   1 root root    0 Aug 10 18:23 file3
-rw-r--r--   1 root root    0 Aug 10 18:23 file2
-rw-r--r--   1 root root   28 Aug 10 18:24 file1
drwxr-xr-x   1 root root 4096 Aug 10 18:38 etc
dr-xr-xr-x 181 root root    0 Aug 10 18:38 proc
drwxr-xr-x   5 root root  360 Aug 10 18:38 dev

See file and packages exists 
root@b95d921f2476:/# tree --version
tree v2.1.1 (c) 1996 - 2023 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
root@b95d921f2476:/# apache2 -v
Server version: Apache/2.4.58 (Ubuntu)
Server built:   2025-07-14T16:22:22

We can called Containerization ,this is called os level virtualization, it main purpose reusability 

DOCKERFILE:
it is an automation way to create image.
here we use components to create image.
in Dockerfile D must be Capital.
Components also capital.
To write our instructions we need to use components in Dockerfile
This Dockerfile will be Reuseable.
here we can create image directly without container help.
Name: Dockerfile 


COMPONENTS:

FROM : used to base image
RUN : used to run linux commands (During image creation)
CMD : used to run linux commands (After container creation)
ENTRYPOINT : high priority than cmd
COPY : to copy local files to container
ADD : to copy internet files to container
WORKDIR : to open req directory
LABEL : to add labels for docker images
ENV : to set env variables (inside container)
ARGS : to pass env variables (outside containers)
EXPOSE : to indicate port number
VOLUME
NETWORK

Step5: for all instruction you need components 

Dockerfile -->image-->container

Kill the container using below command 

root@dockerhost:~# docker ps -a
CONTAINER ID   IMAGE              COMMAND       CREATED          STATUS          PORTS     NAMES
b95d921f2476   ubuntupkh_img:v1   "/bin/bash"   14 minutes ago   Up 14 minutes             container2
adc881f1c093   ubuntu             "/bin/bash"   36 minutes ago   Up 36 minutes             container1
root@dockerhost:~# docker ps -aq
b95d921f2476
adc881f1c093
root@dockerhost:~# docker kill $(docker ps -aq)
b95d921f2476
adc881f1c093
root@dockerhost:~# docker ps -a
CONTAINER ID   IMAGE              COMMAND       CREATED          STATUS                       PORTS     NAMES
b95d921f2476   ubuntupkh_img:v1   "/bin/bash"   15 minutes ago   Exited (137) 8 seconds ago             container2
adc881f1c093   ubuntu             "/bin/bash"   37 minutes ago   Exited (137) 8 seconds ago             container1
 
Remove containers

root@dockerhost:~# docker rm $(docker ps -aq)
b95d921f2476
adc881f1c093
root@dockerhost:~# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Remove images 

root@dockerhost:~# docker images -q
327dee052d80
65ae7a6f3544
root@dockerhost:~# docker images
REPOSITORY      TAG       IMAGE ID       CREATED          SIZE
ubuntupkh_img   v1        327dee052d80   21 minutes ago   245MB
ubuntu          latest    65ae7a6f3544   3 weeks ago      78.1MB
root@dockerhost:~# docker rmi $(docker images -q)
Untagged: ubuntupkh_img:v1
Deleted: sha256:327dee052d80405da2565ef6e042f8e2be3eb5226af23af4217408c8b0d57921
Deleted: sha256:4a286e29abe731e078404a9bdc200ff3cec139e5d69ec2456c3aa0a465973fc1
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
Deleted: sha256:65ae7a6f3544bd2d2b6d19b13bfc64752d776bc92c510f874188bfd404d205a3
Deleted: sha256:107cbdaeec042e6154640c94972c638f4e2fee795902b149e8ce9acbd03d59d7

Step6: Docker file creating steps 

ENTRYPOINT VS CMD:

FROM ubuntu
ENTRYPOINT ["sleep"]
CMD ["1000"]


root@dockerhost:~# vim Dockerfile
root@dockerhost:~# cat Dockerfile
FROM ubuntu
RUN apt update -y
RUN apt install apache2 -y
RUN apt install python3 -y
CMD apt install mysql-server -y

Step7: Build docker image, As see my sql not installed , it is cmd prompt ,so it will run whenevery container creating time

root@dockerhost:~# docker build -t dockerimage:v1 .
Step 5/5 : CMD apt install mysql-server -y
 ---> Running in 72d94de11f19
 ---> Removed intermediate container 72d94de11f19
 ---> 162f726580bf

Successfully built 162f726580bf
Successfully tagged dockerimage:v1

root@dockerhost:~# docker images
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
dockerimage   v1        162f726580bf   34 seconds ago   281MB
ubuntu        latest    65ae7a6f3544   3 weeks ago      78.1MB

Step8: Create container,now see mysql installing 
root@dockerhost:~# docker run -it --name containerdocker1 dockerimage:v1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
Setting up libcgi-fast-perl (1:2.17-1) ...
Setting up mysql-server (8.0.42-0ubuntu0.24.04.2) ...
Processing triggers for libc-bin (2.39-0ubuntu8.5) ...

One more image COPY command existing file copy to /tmp folder ADD command for dowload software from intenet and placing in /tmp folder
Step9: copy and add 

root@dockerhost:~# vi Dockerfile
root@dockerhost:~# cat Dockerfile
FROM ubuntu
COPY index.html /tmp
ADD https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.10/src/apache-tomcat-11.0.10-src.zip /tmp


Step10: now again build new image 

root@dockerhost:~# docker build -t dockercpimage:v2 .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon  30.72kB
Step 1/3 : FROM ubuntu
 ---> 65ae7a6f3544
Step 2/3 : COPY index.html /tmp
 ---> 0087e026e831
Step 3/3 : ADD https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.10/src/apache-tomcat-11.0.10-src.zip /tmp
Downloading [==================================================>]  11.44MB/11.44MB

 ---> 23b4041c4bf6
Successfully built 23b4041c4bf6
Successfully tagged dockercpimage:v2

root@dockerhost:~# docker images
REPOSITORY      TAG       IMAGE ID       CREATED              SIZE
dockercpimage   v2        23b4041c4bf6   About a minute ago   89.6MB
dockerimage     v1        162f726580bf   14 minutes ago       281MB
ubuntu          latest    65ae7a6f3544   3 weeks ago          78.1MB


Step11: Creating Container, now see cp coming local , tomcat coming from internet website
    
root@dockerhost:~# docker run -it --name containercp1 dockercpimage:v2
root@e9429dfc244e:/# cd /tmp
root@e9429dfc244e:/tmp# ls
apache-tomcat-11.0.10-src.zip  index.html


Step12: WORKDIR,LABEL ,build again creating new image 
WORKERDIR it will goto specific path 
LABEL give specific name to image

root@dockerhost:~# docker build -t dockercpimage1:v3 .
root@dockerhost:~# docker build -t dockercpimage1:v3 .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon  31.23kB
Step 1/5 : FROM ubuntu
 ---> 65ae7a6f3544
Step 2/5 : COPY index.html /tmp
 ---> Using cache
 ---> 0087e026e831
Step 3/5 : ADD https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.10/src/apache-tomcat-11.0.10-src.zip /tmp
Downloading [==================================================>]  11.44MB/11.44MB

 ---> Using cache
 ---> 23b4041c4bf6
Step 4/5 : WORKDIR /tmp
 ---> Running in 290cb2b88cd2
 ---> Removed intermediate container 290cb2b88cd2
 ---> aed410d8af71
Step 5/5 : LABEL author vakatisubbu
 ---> Running in 471636289f7c
 ---> Removed intermediate container 471636289f7c
 ---> e2720128a90d
Successfully built e2720128a90d
Successfully tagged dockercpimage1:v3

Step13: it is going automatically temp directory, docker inspect label author name checking with ur name

root@dockerhost:~# docker run -it --name containerwrk2 dockercpimage1:v3
root@2afd2fdc76f3:/tmp#

exit from container ctrl+P+Q
root@2afd2fdc76f3:/tmp# docker inspect root@dockerhost:~#
 

  "Labels": {
                "author": "vakatisubbu",
                "org.opencontainers.image.ref.name": "ubuntu",
                "org.opencontainers.image.version": "24.04"
            }

Step14: ENV for environment variables EXPOSE for container which port to run 

root@dockerhost:~# cat Dockerfile
FROM ubuntu
ENV user vakatisubbu
ENV client swiggy
EXPOSE 8080

Step15: Dockerbuild and create container 
root@dockerhost:~# docker build -t dockerendimage2:v4 .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon  31.23kB
Step 1/4 : FROM ubuntu
 ---> 65ae7a6f3544
Step 2/4 : ENV user vakatisubbu
 ---> Running in c9329776bcde
 ---> Removed intermediate container c9329776bcde
 ---> 1433b1258b7f
Step 3/4 : ENV client swiggy
 ---> Running in 3cfea1ee6546
 ---> Removed intermediate container 3cfea1ee6546
 ---> eeac0fd1965a
Step 4/4 : EXPOSE 8080
 ---> Running in aeb3d9efcf03
 ---> Removed intermediate container aeb3d9efcf03
 ---> 79148bd0f0ce
Successfully built 79148bd0f0ce
Successfully tagged dockerendimage2:v4

root@dockerhost:~# docker images
REPOSITORY        TAG       IMAGE ID       CREATED          SIZE
dockerendimage2   v4        79148bd0f0ce   22 seconds ago   78.1MB
dockercpimage1    v3        e2720128a90d   9 minutes ago    89.6MB
dockercpimage     v2        23b4041c4bf6   18 minutes ago   89.6MB
dockerimage       v1        162f726580bf   31 minutes ago   281MB
ubuntu            latest    65ae7a6f3544   3 weeks ago      78.1MB

Step16:

root@dockerhost:~# docker run -it --name containerenv2 dockerendimage2:v4
root@fc37e72ef91a:/#

username came with your name 
root@fc37e72ef91a:/# echo $user
vakatisubbu
root@fc37e72ef91a:/# echo $client
swiggy

docker running which port 
root@dockerhost:~# docker ps
CONTAINER ID   IMAGE                COMMAND       CREATED              STATUS              PORTS      NAMES
fc37e72ef91a   dockerendimage2:v4   "/bin/bash"   About a minute ago   Up About a minute   8080/tcp   containerenv2
2afd2fdc76f3   dockercpimage1:v3    "/bin/bash"   11 minutes ago       Up 11 minutes                  containerwrk2
e9429dfc244e   dockercpimage:v2     "/bin/bash"   18 minutes ago       Up 18 minutes                  containercp1


Step17: Below official document more comments for refernces
https://docs.docker.com/reference/dockerfile/



 Build one netflex application 

NETFLIX-DEPLOYMENT:

apt install git -y
git clone https://github.com/RAHAMSHAIK007/netflix-clone.git
cd netflix-clone/

Vi Dockerfile

FROM ubuntu
RUN apt update
RUN apt install apache2 -y
COPY * /var/www/html/
CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]


docker build -t netflix:v1 .
docker run -it --name netflix1 -p 80:80 netflix:v1


Step1:

root@dockerhost:~# git clone https://github.com/RAHAMSHAIK007/netflix-clone.git
Cloning into 'netflix-clone'...
remote: Enumerating objects: 130, done.
remote: Counting objects: 100% (20/20), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 130 (delta 14), reused 1 (delta 1), pack-reused 110 (from 2)
Receiving objects: 100% (130/130), 47.61 KiB | 4.76 MiB/s, done.
Resolving deltas: 100% (75/75), done.
root@dockerhost:~# pwd
/root
root@dockerhost:~# cd netflix-clone/

Step2: Create one docker file here 
root@dockerhost:~/netflix-clone# ls -lrt
total 56
-rw-r--r-- 1 root root  106 Aug 10 19:50 README.md
-rw-r--r-- 1 root root 2829 Aug 10 19:50 style.css
-rw-r--r-- 1 root root  666 Aug 10 19:50 session.js
-rw-r--r-- 1 root root 6706 Aug 10 19:50 script.js
-rw-r--r-- 1 root root 1018 Aug 10 19:50 register.js
-rw-r--r-- 1 root root 2908 Aug 10 19:50 register.html
-rw-r--r-- 1 root root  574 Aug 10 19:50 register.css
-rw-r--r-- 1 root root 1846 Aug 10 19:50 plan.md
-rw-r--r-- 1 root root 1163 Aug 10 19:50 login.js
-rw-r--r-- 1 root root 2672 Aug 10 19:50 login.html
-rw-r--r-- 1 root root  698 Aug 10 19:50 login.css
-rw-r--r-- 1 root root 3609 Aug 10 19:50 index.html
drwxr-xr-x 2 root root 4096 Aug 10 19:50 assets

Step3:CMD ["/usr/sbin/apachectl","FOREGROUND"] ,this command if you exit from the container,
even though apachectl run ,it will  foreground from backend


root@dockerhost:~/netflix-clone# vi Dockerfile
root@dockerhost:~/netflix-clone# cat Dockerfile
FROM ubuntu
RUN apt update -y
RUN apt install apache2 -y
COPY * /var/www/html/
CMD ["/usr/sbin/apachectl","-D","FOREGROUND"]


Step4:

root@dockerhost:~/netflix-clone# docker build -t dockernetflexfinal .

Successfully built 727cd091145b
Successfully tagged dockernetflexfinal:latest
root@dockerhost:~/netflix-clone# docker images
REPOSITORY           TAG       IMAGE ID       CREATED          SIZE
dockernetflexfinal   latest    727cd091145b   22 seconds ago   245MB
dockernetflex        v4        ae3c756c75a6   11 minutes ago   245MB
dockernetflex        latest    c6219b442e36   22 minutes ago   245MB
dockernetflex        v1        c6219b442e36   22 minutes ago   245MB
ubuntu               latest    65ae7a6f3544   3 weeks ago      78.1MB


Step5: 
root@dockerhost:~/netflix-clone# docker run -it --name containernetfinal -p 83:80  dockernetflexfinal
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message


Step6:



Step7: if you want change any some line code in login page you edit can build create container 
for ex:  NETFLEX V-4.0 changed to NETFLEX V-5.0


Step8:

root@dockerhost:~/netflix-clone# docker build -t dockernetflexfinal1 .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon  185.3kB
Step 1/5 : FROM ubuntu
 ---> 65ae7a6f3544
Step 2/5 : RUN apt update -y
 ---> Using cache
 ---> f2511e97f53b
Step 3/5 : RUN apt install apache2 -y
 ---> Using cache
 ---> aff58ac566bc
Step 4/5 : COPY * /var/www/html/
 ---> ec7b4377c133
Step 5/5 : CMD ["/usr/sbin/apachectl","-D","FOREGROUND"]
 ---> Running in 1dee218601b8
 ---> Removed intermediate container 1dee218601b8
 ---> 5f0d03a2fc93
Successfully built 5f0d03a2fc93
Successfully tagged dockernetflexfinal1:latest
root@dockerhost:~/netflix-clone# docker run -it --name containernetfinal1 -p 84:80  dockernetflexfinal1

Step9:



--Thanks 

Friday, August 1, 2025

Docker Part1

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 

root@92dc1437896a:/#
exit

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