docker-compose部署java项目 jdk+mysql+redis

   docker-compose部署java项目  jdk+mysql+redis

我的目录是Dockerfile,docker-compose.yml文件,mysql文件夹,redis文件夹,java文件夹

 

Dockerfile:

  

FROM java:8

MAINTAINER "jianle"

VOLUME /tmp
ADD *.jar /app.jar
RUN sh -c 'touch /app.jar'
EXPOSE 19000
ENV JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF8 -Duser.timezone=GMT+08"
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

 

 

docker-compose.yml:

version: "3"
# 管理的服务
services:
mysql:
restart: always
image: mysql:8.0.26
container_name: mysql
privileged: true
ports:
- 3306:3306
volumes:
- "./mysql/data:/var/lib/mysql"
- "./mysql/mysql-files:/var/lib/mysql-files"
- "./mysql/my.cnf:/etc/mysql/my.cnf"
environment:
# 环境变量
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=123456
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--max_allowed_packet=128M
--sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
networks:
mynetwork:
ipv4_address: 192.168.0.5
redis:
# 指定镜像
restart: always
image: redis:6.2.6
container_name: redis
privileged: true
ports:
# 端口映射
- 6379:6379
volumes:
# 目录映射
- "./redis/redis.conf:/usr/local/etc/redis/redis.conf"
- "./redis/data:/data"
command:
# 执行的命令
redis-server /usr/local/etc/redis/redis.conf
networks:
mynetwork:
ipv4_address: 192.168.0.6

app:
restart: always
build:
context: . #Dockerfile 所在目录
dockerfile: Dockerfile
privileged: true
container_name: app
environment:
- TZ=Asia/Shanghai
volumes:
- "./java/logs:/logs"
ports:
- 19000:19000
depends_on:
- mysql
- redis
networks:
mynetwork:
ipv4_address: 192.168.0.7
networks:
mynetwork:
ipam:
driver: default
config:
- subnet: "192.168.0.0/24"

 

 

mysql文件夹中的my.conf  (其他的两个是数据文件,会自动生成, my.cnf我只列出mysqld下的配置)

[mysqld]
lower_case_table_names = 1
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL

 

redis文件夹中的redis.conf

#配置redis密码
requirepass 123456

 

 

有需要的可以借鉴参考下

 

上一篇:Docker服务编排


下一篇:docker