-
Notifications
You must be signed in to change notification settings - Fork 0
/
Docker Compose Commands.txt
229 lines (171 loc) · 3.74 KB
/
Docker Compose Commands.txt
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
1)
build option:
mkdir composetest
cd composetest
vim dockerfile
ARG Version
FROM ubuntu:$Version
MAINTAINER Prasanti
RUN apt-get update
RUN apt-get install -y iputils-ping
CMD sleep 3000
vim docker-compose.yml
version: "3.8"
services:
webapp:
build:
context: .
dockerfile: dockerfile
args:
Version: "latest"
docker-compose up -d
vim docker-compose1.yml
version: "3.8"
services:
webapp:
image: nginx:latest
docker-compose -f docker-compose1.yml up
2) environment option
cd composetest
vim dockerfile5
FROM ubuntu:latest
MAINTAINER Prasanti
ENV sample=hello
RUN apt-get update
RUN apt-get install -y iputils-ping
RUN mkdir $sample
CMD echo $sample
cd ..
vim docker-compose5.yml
version: "3.8"
services:
webapp5:
build:
context: .
dockerfile: dockerfile
image: myubuntuimage:latest
environment:
sample: helloworld
docker-compose -f docker-compose5.yml up
3) image and ports:
example:
vim docker-compose2.yml
version: "3.8"
services:
webapp1:
build:
context: ./composetest
dockerfile: dockerfile
args:
Version: "latest"
image : myubuntu
docker-compose -f docker-compose2.yml up
example 2:
vim docker-compose6.yml
version: "3.8"
services:
webapp6:
image : nginx
ports:
- "8080:80"
docker-compose -f docker-compose6.yml up
4) Networking
example:
vim docker-compose10.yml
version: "3.8"
services:
web:
image: nginx:alpine
volumes:
- type: volume
source: mydata1
target: /data
volume:
nocopy: true
networks:
- frontend
- existingnetwork
db:
image: postgres:latest
environment:
POSTGRES_PASSWORD: mysecretpassword
volumes:
- "/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock"
- "dbdata:/var/lib/postgresql/data"
networks:
- frontend
- existingnetwork
volumes:
mydata1:
dbdata:
networks:
frontend:
driver: bridge
existingnetwork:
external:
name: mybridge
docker-compose -f docker-compose10.yml up -d
docker exec -it root_db_1 /bin/bash
apt-get update
apt-get install -y iputils-ping
5) Volumes:
vim docker-compose9.yml
version: "3.8"
services:
web:
image: nginx:alpine
volumes:
- type: volume
source: mydata1
target: /data
volume:
nocopy: true
db:
image: postgres:latest
environment:
POSTGRES_PASSWORD: mysecretpassword
volumes:
- "/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock"
- "dbdata:/var/lib/postgresql/data"
volumes:
mydata1:
dbdata:
docker-compose -f docker-compose9.yml up
6) deploy:
docker swarm init --advertise-addr 192.168.0.28
vim docker-compose11.yml
version: "3.8"
services:
redis:
image: redis:alpine
deploy:
replicas: 2
placement:
max_replicas_per_node: 1
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
db:
image: postgres
deploy:
replicas: 2
docker-compose -f docker-compose11.yml up -d
docker stack deploy -c docker-compose11.yml MySTACK
7) rollback / update config:
vim dc.yml
version: "3.8"
services:
vote:
image: nginx:latest
deploy:
replicas: 2
update_config:
parallelism: 2
delay: 10s
order: stop-first
restart_policy:
condition: on-failure
docker stack deploy -c dc.yml STACK2
docker service update --image nginx:stable-perl STACK2_vote