我在这个问题上苦苦挣扎了几个小时。 我有以下设置:
Dockerfile
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/ROOT.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","app.jar","--spring.profiles.active=dev"]
EXPOSE 8080
docker-compose.yml
version: '3'
services:
app:
container_name: app
build:
context: .
dockerfile: Dockerfile
restart: always
links:
- mysql-db
depends_on:
- mysql-db
ports:
- 8080:8080
expose:
- 8080
networks:
- spring-network
mysql-db:
restart: always
container_name: mysql_db
image: "mysql:8.0.19"
ports:
- 3306:3306
networks:
- spring-network
environment:
MYSQL_ROOT_PASSWORD: 'password'
MYSQL_DATABASE: 'db'
MYSQL_USER: 'db-user'
MYSQL_PASSWORD: 'password'
volumes:
- mysql-db:/var/lib/mysql
command: --innodb-use-native-aio=0
security_opt:
- seccomp:unconfined
volumes:
mysql-db:
networks:
spring-network:
driver: bridge
当我使用docker-compose up
运行应用程序时,它在容器中运行良好,但是当我在浏览器中访问localhost:8080时,我得到了
localhost意外关闭了连接
编辑: