サンプル: Dockerfile記述例¶
ここでは始めの一歩として簡単なWebサーバを起動するコンテナとアプリケーションサーバ、 MySQLの例を記載します。 docker-composeファイルをサンプルとしてみます
オリジナルでイメージを作成するコンテナはDockerfileを確認ください。
version: '2'
services:
sample-app:
image: sample
environment:
- SPRING_PROFILES_ACTIVE=prod,swagger
- SPRING_DATASOURCE_URL=jdbc:mysql://sample-mysql:3306/sample?useUnicode=true&characterEncoding=utf8&useSSL=false
- JHIPSTER_SLEEP=10 # gives time for the database to boot before the application
- SPRING_DATA_ELASTICSEARCH_CLUSTER_NODES=sample-elasticsearch:9300
ports:
- 8080:8080
sample-mysql:
extends:
file: mysql.yml
service: sample-mysql
sample-elasticsearch:
extends:
file: elasticsearch.yml
service: sample-elasticsearch
FROM openjdk:8-jre-alpine
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
JHIPSTER_SLEEP=0 \
JAVA_OPTS=""
CMD echo "The application will start in ${JHIPSTER_SLEEP}s..." && \
sleep ${JHIPSTER_SLEEP} && \
java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.war
EXPOSE 8080
ADD *.war /app.war
version: '2'
services:
sample-elasticsearch:
image: elasticsearch:2.4.6
# volumes:
# - ~/volumes/jhipster/sample/elasticsearch/:/usr/share/elasticsearch/data/
ports:
- 9200:9200
- 9300:9300
version: '2'
services:
sample-mysql:
image: mysql:5.7.20
# volumes:
# - ~/volumes/jhipster/sample/mysql/:/var/lib/mysql/
environment:
- MYSQL_USER=root
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=sample
ports:
- 3306:3306
command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8 --explicit_defaults_for_timestamp
version: '2'
services:
sample-sonar:
image: sonarqube:6.5-alpine
ports:
- 9000:9000
- 9092:9092