質問編集履歴

1

Docker周りの設定の内容を追加

2021/02/02 06:41

投稿

Anmos
Anmos

スコア1

test CHANGED
File without changes
test CHANGED
@@ -71,3 +71,291 @@
71
71
  MacOS
72
72
 
73
73
  DockerforMac
74
+
75
+
76
+
77
+ http://joytas.net/programming/jspservlet08
78
+
79
+ こちらのサイトのようなプログラムをDockerで作りたい
80
+
81
+ Dockerの設定はこのサイトを参考にしています。(https://ucwork.hatenablog.com/entry/2018/08/19/172548)
82
+
83
+ プログラムをビルドし、できたwarをデプロイするところをDockerで実現する箇所を自分で追加しようと思い、躓いています。
84
+
85
+
86
+
87
+ * 現状のディレクトリ構成
88
+
89
+ ```
90
+
91
+ .
92
+
93
+ ├── docker
94
+
95
+ │ ├── mysql01
96
+
97
+ │ │ ├── Dockerfile
98
+
99
+ │ │ └── config
100
+
101
+ │ │ └── charset.cnf
102
+
103
+ │ ├── nginx01
104
+
105
+ │ │ ├── Dockerfile
106
+
107
+ │ │ └── conf
108
+
109
+ │ │ └── nginx.conf
110
+
111
+ │ └── tomcat01
112
+
113
+ │ ├── Dockerfile
114
+
115
+ │ ├── conf
116
+
117
+ │ │ └── supervisord.conf
118
+
119
+ │ └── deployment
120
+
121
+ ├── docker-compose.yml
122
+
123
+
124
+
125
+ ```
126
+
127
+ * docker-compose.yml
128
+
129
+ ```
130
+
131
+ version: '3'
132
+
133
+ services:
134
+
135
+ web01:
136
+
137
+ container_name: nginx01
138
+
139
+ build: ./docker/nginx01
140
+
141
+ image: nginx01:1.0.0
142
+
143
+ ports:
144
+
145
+ - "80:80"
146
+
147
+ environment:
148
+
149
+ TZ: "Asia/Tokyo"
150
+
151
+ volumes:
152
+
153
+ - ./docker/nginx01/conf:/etc/nginx/conf.d
154
+
155
+ extra_hosts:
156
+
157
+ - "tournament.local:127.0.0.1"
158
+
159
+ servlet01:
160
+
161
+ container_name: tomcat01
162
+
163
+ build: ./docker/tomcat01
164
+
165
+ image: tomcat01:1.0.0
166
+
167
+ environment:
168
+
169
+ TZ: "Asia/Tokyo"
170
+
171
+ expose:
172
+
173
+ - "8080"
174
+
175
+ ports:
176
+
177
+ - "8000:8000"
178
+
179
+ volumes:
180
+
181
+ - ./docker/tomcat01/deployment:/usr/local/tomcat/webapps/:rw
182
+
183
+ db01:
184
+
185
+ container_name: mysql01
186
+
187
+ build: ./docker/mysql01
188
+
189
+ image: mysql01:1.0.0
190
+
191
+ command: >-
192
+
193
+ /entrypoint.sh mysqld
194
+
195
+ --slow_query_log=3
196
+
197
+ --long_query_time=3
198
+
199
+ --slow_query_log_file=/var/log/mysql/slow.log
200
+
201
+ environment:
202
+
203
+ MYSQL_ROOT_PASSWORD: root
204
+
205
+ MYSQL_DATABASE: tournament
206
+
207
+ TZ: "Asia/Tokyo"
208
+
209
+ ports:
210
+
211
+ - "3306:3306"
212
+
213
+ volumes:
214
+
215
+ - data:/var/lib/mysql
216
+
217
+ volumes:
218
+
219
+ data: {}
220
+
221
+ ```
222
+
223
+ * Nginx設定ファイル
224
+
225
+ ```
226
+
227
+ server {
228
+
229
+ listen 80;
230
+
231
+ server_name tournament.local;
232
+
233
+
234
+
235
+ access_log /var/log/nginx/tomcat_access.log;
236
+
237
+ error_log /var/log/nginx/tomcat_error.log;
238
+
239
+
240
+
241
+ location / {
242
+
243
+ proxy_set_header X-Forwarded-Host $host:$server_port;
244
+
245
+ proxy_set_header X-Forwarded-Server $host;
246
+
247
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
248
+
249
+ proxy_pass http://servlet01:8080/tournament/;
250
+
251
+ index index.html index.htm;
252
+
253
+ }
254
+
255
+ }
256
+
257
+ ```
258
+
259
+ * Tomcat DockerFile 、設定ファイル
260
+
261
+ ```
262
+
263
+ FROM tomcat:8.0-jre8-alpine
264
+
265
+
266
+
267
+ # set server defautlt setting
268
+
269
+ RUN apk --update add tzdata perl curl openssh openrc supervisor && \
270
+
271
+ rm -rf /var/cache/apk/*
272
+
273
+ ENV TZ Asia/Tokyo
274
+
275
+
276
+
277
+ # access to velocity frmo jboss
278
+
279
+ ENV JAVA_OPTS="-Dspring.profiles.active=local"
280
+
281
+ ENV JPDA_ADDRESS=8000
282
+
283
+ ENV JPDA_TRANSPORT=dt_socket
284
+
285
+
286
+
287
+ # start tomcat & sshd
288
+
289
+ COPY ./conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
290
+
291
+ CMD /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
292
+
293
+ ```
294
+
295
+ ```
296
+
297
+ [supervisord]
298
+
299
+ nodaemon=true
300
+
301
+
302
+
303
+ [program:sshd]
304
+
305
+ command=/usr/sbin/sshd -D
306
+
307
+
308
+
309
+ [program:tomcat]
310
+
311
+ command=/usr/local/tomcat/bin/catalina.sh jpda run
312
+
313
+ ```
314
+
315
+ * MySQL DockerFile 、設定ファイル
316
+
317
+ ```
318
+
319
+ FROM mysql:5.6
320
+
321
+
322
+
323
+ # 設定ファイルを配置
324
+
325
+ # (MySQLは設定ファイルの権限が777だと読み込まない)
326
+
327
+ COPY config /etc/mysql/conf.d/
328
+
329
+ RUN chmod 644 /etc/mysql/conf.d/*
330
+
331
+
332
+
333
+ RUN apt-get update && \
334
+
335
+ apt-get install -y locales && \
336
+
337
+ rm -rf /var/lib/apt/lists/* && \
338
+
339
+ echo "ja_JP.UTF-8 UTF-8" > /etc/locale.gen && \
340
+
341
+ locale-gen ja_JP.UTF-8
342
+
343
+ ENV LC_ALL ja_JP.UTF-8
344
+
345
+ ```
346
+
347
+ ```
348
+
349
+ [mysqld]
350
+
351
+ explicit_defaults_for_timestamp = 1
352
+
353
+ character-set-server=utf8
354
+
355
+ sql_mode=NO_ENGINE_SUBSTITUTION
356
+
357
+ [mysql]
358
+
359
+ default-character-set=utf8
360
+
361
+ ```