1. 把脚本复制到镜像内
Dockerfile中
COPY wait-for-it.sh /usr/local/bin/
2.在docker-compose.yml中修改添加
entrypoint: “bash /usr/local/bin/wait-for-it.sh mysql:3306 – java -jar /safebox-eureka.jar”
示例:
*version: ‘2.4’
services:
eureka:
image: wait-for-it-test:v1
ports:
- “8761:8761”
container_name: safebox-eureka #自定义容器名
depends_on:
- mysql
entrypoint: “bash /usr/local/bin/wait-for-it.sh mysql:3306 – java -jar /safebox-eureka.jar”
mysql:
container_name: safebox-mysql
environment:
MYSQL_ROOT_PASSWORD: bcrdb
image: domain.cn/safebox/mysql-123456:v5.7
restart: always
volumes:
- /apps/svr/docker/dockercompose/mysql/lib/mysql:/var/lib/mysql
#删除容器后重新创建容器只要这个挂载的数据文件夹没变,数据库数据就和之前一样。
ports:
- 3306:3306*