Home > Net >  docker-compose error when creating MySQL database container
docker-compose error when creating MySQL database container

Time:03-09

I have the following docker-compose.yml and Dockerfile in my Spring Boot app but when I run docker-compose up -d, I get the following error:

"failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount967315702/Dockerfile: no such file or directory"

As I use Windows10, I think I need some tweaks related to the WORKDIR, etc. I have WSL where Docker installed). But even I tried different combinations, I have not managed to fix the problem.

Here is the docker-compose.yml and Dockerfile in my root project folder (springboot-backend):

docker-compose.yml: I am not sure about

version: "3.8"
services:
  mysqldb:
    image: mysql:5.7
    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: ./springboot-backend
    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:

Dockerfile:

FROM maven:3.8.2-jdk-8
WORKDIR /springboot-backend
COPY . .
RUN mvn clean install
CMD mvn spring-boot:run

.env file:

MYSQLDB_USER=root
MYSQLDB_ROOT_PASSWORD=******
MYSQLDB_DATABASE=employee_management_system
MYSQLDB_LOCAL_PORT=3307
MYSQLDB_DOCKER_PORT=3306
SPRING_LOCAL_PORT=6868
SPRING_DOCKER_PORT=8080

Any idea?

Here is folder structure:

enter image description here

CodePudding user response:

app:
    depends_on:
      - mysqldb
    build: ./springboot-backend

Docker compose yaml try to build springboot-backend but there is no such directory in the same path of compose yaml. Just simply you can move docker-compose yaml to outside of springboot-backend project folder.

  • Related