创建docker-compose.yml文件
version: '3'
services:
canteenredis:
image: redis:5.0.5
container_name: canteenredis
command: redis-server /usr/local/etc/redis/redis.conf
volumes:
- ./redis/data:/data
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf
- /etc/localtime:/etc/localtime:ro
environment:
- TZ=Asia/Shanghai
restart: always
ports:
- "6380:6379"
canteenmysql:
image: mysql:8.0.17
command: --default-authentication-plugin=mysql_native_password
restart: always
container_name: canteenmysql
environment:
MYSQL_DATABASE: canteen_dev
MYSQL_ROOT_PASSWORD: root321
volumes:
- "./mysql/db:/var/lib/mysql"
- "./mysql/conf/my.cnf:/etc/my.cnf"
- "./mysql/init:/docker-entrypoint-initdb.d/"
- "/etc/localtime:/etc/localtime:ro"
ports:
- '3307:3306'
canteennginx:
image: nginx:1.17.2
container_name: canteennginx
volumes:
- ./nginx/mysite.template:/etc/nginx/conf.d/mysite.template
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/log/:/var/log/nginx
- ./nginx/html/:/usr/share/nginx/html
- /etc/localtime:/etc/localtime:ro
restart: always
ports:
- "8282:8282"
environment:
- NGINX_HOST=foobar.com
- NGINX_PORT=80
command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
canteenserver:
image: jdk:8u131server
container_name: canteenserver
build:
context: ./jdk
dockerfile: DockerfileFace
restart: always
tty: true
volumes:
- ./jdk/java:/usr/work/java
- /etc/localtime:/etc/localtime:ro
environment:
- TZ=Asia/Shanghai
ports:
- "8686:8080"
depends_on:
- canteenredis
- canteenmysql
- canteennginx
将项目放置jdk/java/目录下修改DockerfileFace CMD,将前端页面放至nginx/html/canteenpage下修改nginx配置