[ BAEL-5503 ] - Difference Between links and depends_on in Docker-Compose (#12503)

* updates pom-xml and adds Dockerfile to build a web-app image

* add depends-on vs links yml examples
This commit is contained in:
lucaCambi77 2022-07-16 17:37:07 +02:00 committed by GitHub
parent b6e04505ef
commit 09651da81e
5 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,4 @@
FROM openjdk:11
MAINTAINER baeldung.com
COPY target/docker-compose-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

View File

@ -0,0 +1,14 @@
services:
db:
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
web-app:
image: web-app:latest
ports:
- 8080:8080
depends_on:
- db

View File

@ -0,0 +1,14 @@
services:
db:
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
web-app:
image: web-app:latest
ports:
- 8080:8080
links:
- db

View File

@ -0,0 +1,36 @@
services:
db:
image: postgres:latest
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
volumes:
- db:/var/lib/postgresql/data
networks:
- mynet
web-app:
image: web-app:latest
depends_on:
- db
networks:
- mynet
ports:
- 8080:8080
environment:
DB_HOST: db
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: postgres
networks:
mynet:
driver: bridge
volumes:
db:
driver: local

View File

@ -34,6 +34,16 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.baeldung.docker.app.DockAppApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>