I am trying to build a local network for two services with a docker compose file. service mysqldb - the data base for the spring boot app. service app - the spring boot app.
this is the error i am receiving:
these are my files
Dockerfile
FROM maven:3.8.3-jdk-8
WORKDIR /mile-restoraunt-app
COPY . .
RUN mvn clean install
CMD mvn spring-boot:run
docker-compose.yml file
version: "3.8"
services:
mysqldb:
image: mysql
restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD
- MYSQL_DATABASE=$MYSQLDB_DATABASE
ports:
- $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT
volumes:
- db:/var/lib/mysql
app:
depends_on:
- mysqldb
build: ./mile-restoraunt-app
restart: on-failure
env_file: ./.env
ports:
- $SPRING_LOCAL_PORT:$SPRING_DOCKER_PORT
environment:
SPRING_APPLICATION_JSON: '{
"spring.datasource.url" : "jdbc:mysql://mysqldb:$MYSQLDB_DOCKER_PORT/$MYSQLDB_DATABASE?useSSL=false",
"spring.datasource.username" : "$MYSQLDB_USER",
"spring.datasource.password" : "$MYSQLDB_ROOT_PASSWORD",
"spring.jpa.properties.hibernate.dialect" : "org.hibernate.dialect.MySQL5InnoDBDialect",
"spring.jpa.hibernate.ddl-auto" : "update"
}'
volumes:
- .m2:/root/.m2
stdin_open: true
tty: true
volumes:
db:
.env file
MYSQLDB_USER=root
MYSQLDB_ROOT_PASSWORD=thanatos
MYSQLDB_DATABASE=restaurant
MYSQLDB_LOCAL_PORT=3307
MYSQLDB_DOCKER_PORT=3306
SPRING_LOCAL_PORT=6868
SPRING_DOCKER_PORT=8080
And this is my directory
CodePudding user response:
in docker-compose.yaml
for a app
you specified build: ./mile-restoraunt-app
, but you run your command inside the mile-restoraunt-app
folder. You need to change the build folder.