0

I have a problem when I try to run two Spring Boot microservices. This is how my docker-compose.yml looks like:

version: '3.3'

services:
  clients:
    image: clients
    build: GunShop-Clients-SB\src\main\docker
    container_name: clients
    ports:
      - 8081:8081
    depends_on:
      - dbpostgresql
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://dbpostgresql:5432/microservices
      - SPRING_DATASOURCE_USERNAME=postgres
      - SPRING_DATASOURCE_PASSWORD=portocaliu
      - spring.jpa.generate-ddl=true
      - spring.jpa.hibernate.ddl-auto=update

  gun-types:
    image: gun-types
    build: GunShop-GunTypes-SB\src\main\docker
    container_name: gun-types
    ports:
      - 8081:8082
    depends_on:
      - dbpostgresql
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://dbpostgresql:5432/microservices
      - SPRING_DATASOURCE_USERNAME=postgres
      - SPRING_DATASOURCE_PASSWORD=portocaliu
      - spring.jpa.generate-ddl=true
      - spring.jpa.hibernate.ddl-auto=update

  dbpostgresql:
    image: postgres:13.2
    container_name: dbpostgresql
    ports:
    - 5432:5432
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=portocaliu
      - POSTGRES_DB=microservices

And I kept the Dockerfile as simple as possible:

FROM openjdk:11
EXPOSE 8081
COPY ../../../build/libs/GunShop-Clients-SB-0.0.1-SNAPSHOT.jar GunShop-Clients-SB-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","GunShop-Clients-SB-0.0.1-SNAPSHOT.jar"]

The Docker file of the other service looks about the same(just different names). These two Dockerfiles are one per each project and the docker-compose is in the exterior of them. So, if I comment the "gun-types" service, having only "clients" and "dbpostgresql" running, my REST API will work. But when I have also the "gun-types" service I will get the error:

=> ERROR [2/2] COPY ../../../build/libs/GunShop-GunTypes-SB-0.0.1-SNAPSHOT.jar GunShop-GunTypes-SB-0.0.1-SNAPSHO  0.0s
------
 > [2/2] COPY ../../../build/libs/GunShop-GunTypes-SB-0.0.1-SNAPSHOT.jar GunShop-GunTypes-SB-0.0.1-SNAPSHOT.jar:
------
failed to compute cache key: failed to walk /var/lib/docker/tmp/buildkit-mount651808317/build/libs: lstat /var/lib/docke
r/tmp/buildkit-mount651808317/build/libs: no such file or directory
ERROR: Service 'gun-types' failed to build : Build failed
`docker-compose` process finished with exit code 1

I just can't figure out why this happens. Can somebody help me, please?

hackermanwow
  • 13
  • 1
  • 5
  • I am not sure whether this is related to the problems, but in the port mappings, the 1st value is the **host's** port, while the 2nd value is the **container's** port. Both spring-boot services bind to the same host port (`8081`). – Turing85 May 29 '21 at 22:26
  • I changed to "8082:8082" in the second and the same error happens – hackermanwow May 29 '21 at 22:31
  • Also if I comment the "clients" service, having the remaining "gun-types" and the database, I will get the same error – hackermanwow May 29 '21 at 22:41
  • 1
    You can't `COPY ../...`. In the `docker-compose.yml` you need to set something like `build: { context: ., dockerfile: component/src/main/docker }`, and then change the `COPY` lines to be relative to that `context` directory. – David Maze May 29 '21 at 22:47
  • I'm soryy @DavidMaze, but I don't understand exactly what I have to do – hackermanwow May 29 '21 at 22:53

0 Answers0