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
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
No comments:
Post a Comment