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?