下面是我的docker-compose.yml,它组成了两个docker文件:
mysql.dockerfile
FROM mysql:8
ADD DockerImages/mysql /docker-entrypoint-initdb.d/
springapp.dockerfile
FROM maven:3.5-jdk-8 <br>
ADD target/users-mysql.jar users-mysql.jar<br>
ENTRYPOINT ["/usr/bin/java"]<br>
CMD ["-jar", "users-mysql.jar"]<br>
VOLUME /var/lib/spring-cloud/config-repo
搬运工-compose.yml
版本:'3'
services:
springapp:
build:
context: .
dockerfile: springapp.dockerfile
expose:
- "8888"
ports:
- 8888:8888
links:
- mysqldb:mysqldb
networks:
- spring-demo-network
depends_on:
- mysqldb
environment:
- DATABASE_HOST=mysqldb
- DATABASE_USER=gl_user
- DATABASE_PASSWORD=global@123
- DATABASE_NAME=test_db
mysqldb:
build:
context: .
dockerfile: mysql.dockerfile
ports:
- 3306:3306
container_name : mysql-standalone
networks:
- spring-demo-network
environment:
MYSQL_DATABASE: test_db
MYSQL_USER: gl_user
MYSQL_PASSWORD: global@123
MYSQL_ROOT_PASSWORD: root
MYSQL_ROOT_HOST: '%'
networks:
spring-demo-network:
driver: bridge
我无法连接到数据库,因此会抛出多个错误 错误: