-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathday-11
More file actions
138 lines (101 loc) · 3.78 KB
/
day-11
File metadata and controls
138 lines (101 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
vim Dockerfile
FROM ubuntu
RUN apt update -y
RUN apt install apache2 -y
COPY index.html /var/www/html
CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]
Index.html: take form w3 schools
docker build -t movies:v1 .
docker run -itd --name movies -p 81:80 movies:v1
docker build -t train:v1 .
docker run -itd --name train -p 82:80 train:v1
docker build -t dth:v1 .
docker run -itd --name dth -p 83:80 dth:v1
docker build -t recharge:v1 .
docker run -itd --name recharge -p 84:80 recharge:v1
docker ps -a -q : to list container ids
docker kill $(docker ps -a -q) : to kill all containers
docker rm $(docker ps -a -q) : to remove all containers
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.
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
ls /usr/local/bin/
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose version
NOTE: linux will not give some commands, so to use them we need to download seperately
once a command is downloaded we need to move it to /usr/local/bin
because all the user executed commands in linux will store in /usr/local/bin
executebel permission need to execute the command
vim docker-compose.yml
version: '3.8'
services:
movies:
image: movies:v1
ports:
- "81:80"
train:
image: train:v1
ports:
- "82:80"
dth:
image: dth:v1
ports:
- "83:80"
recharge:
image: recharge:v1
ports:
- "84:80"
COMMANDS:
docker-compose up -d : to create and start all containers
docker-compose stop : to stop all containers
docker-compose start : to start all containers
docker-compose kill : to kill all containers
docker-compose rm : to delete all containers
docker-compose down : to stop and delete all containers
docker-compose pause : to pause all containers
docker-compose unpause : to unpause all containers
docker-compose ps -a : to list the containers managed by compose file
docker-compose images : to list the images managed by compose file
docker-compose logs : to show logs of docker compose
docker-compose top : to show the process of compose containers
docker-compose restart : to restart all the compose containers
docker-compose scale train=10 : to scale the service
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
images we create on server.
these images will work on only this server.
git (local) -- > github (internet) = to access by others
image (local) -- > dockerhub (internet) = to access by others
STEPS:
create dockerhub account
create a repo
docker tag movies:v1 abduljavvadkhan786/movies
docker login -- > username and password
docker push abduljavvadkhan786/movies
docker tag train:v1 abduljavvadkhan786/train
docker push abduljavvadkhan786/train
docker tag dth:v1 abduljavvadkhan786/dth
docker push abduljavvadkhan786/dth
docker tag recharge:v1 abduljavvadkhan786/recharge
docker push abduljavvadkhan786/recharge
docker rmi -f $(docker images -q)
DOCKER SAVE:
docker image save swiggy:v1 > swiggy:v1.tar
docker image history swiggy:v1
docker rmi swiggy:v1
docker images
docker image load < swiggy\:v1.tar
COMMAND TO ZIP: gzip dummy:v5.tar abc.zip