Skip to content

Commit 09651da

Browse files
authored
[ 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
1 parent b6e0450 commit 09651da

5 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM openjdk:11
2+
MAINTAINER baeldung.com
3+
COPY target/docker-compose-0.0.1-SNAPSHOT.jar app.jar
4+
ENTRYPOINT ["java","-jar","/app.jar"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
db:
3+
image: postgres:latest
4+
environment:
5+
- POSTGRES_USER=postgres
6+
- POSTGRES_PASSWORD=postgres
7+
ports:
8+
- 5432:5432
9+
web-app:
10+
image: web-app:latest
11+
ports:
12+
- 8080:8080
13+
depends_on:
14+
- db
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
db:
3+
image: postgres:latest
4+
environment:
5+
- POSTGRES_USER=postgres
6+
- POSTGRES_PASSWORD=postgres
7+
ports:
8+
- 5432:5432
9+
web-app:
10+
image: web-app:latest
11+
ports:
12+
- 8080:8080
13+
links:
14+
- db
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
services:
2+
db:
3+
image: postgres:latest
4+
restart: always
5+
environment:
6+
- POSTGRES_USER=postgres
7+
- POSTGRES_PASSWORD=postgres
8+
ports:
9+
- 5432:5432
10+
volumes:
11+
- db:/var/lib/postgresql/data
12+
networks:
13+
- mynet
14+
15+
web-app:
16+
image: web-app:latest
17+
depends_on:
18+
- db
19+
networks:
20+
- mynet
21+
ports:
22+
- 8080:8080
23+
environment:
24+
DB_HOST: db
25+
DB_PORT: 5432
26+
DB_USER: postgres
27+
DB_PASSWORD: postgres
28+
DB_NAME: postgres
29+
30+
networks:
31+
mynet:
32+
driver: bridge
33+
34+
volumes:
35+
db:
36+
driver: local

docker-modules/docker-compose/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
<plugin>
3535
<groupId>org.springframework.boot</groupId>
3636
<artifactId>spring-boot-maven-plugin</artifactId>
37+
<configuration>
38+
<mainClass>com.baeldung.docker.app.DockAppApplication</mainClass>
39+
</configuration>
40+
<executions>
41+
<execution>
42+
<goals>
43+
<goal>repackage</goal>
44+
</goals>
45+
</execution>
46+
</executions>
3747
</plugin>
3848
</plugins>
3949
</build>

0 commit comments

Comments
 (0)