From 09651da81e8bf50eca49cfd9a5056e408d19edc5 Mon Sep 17 00:00:00 2001 From: lucaCambi77 Date: Sat, 16 Jul 2022 17:37:07 +0200 Subject: [PATCH] [ 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 --- docker-modules/docker-compose/Dockerfile | 4 +++ .../docker-compose-depends-on.yml | 14 ++++++++ .../docker-compose-links.yml | 14 ++++++++ .../docker-compose-network.yml | 36 +++++++++++++++++++ docker-modules/docker-compose/pom.xml | 10 ++++++ 5 files changed, 78 insertions(+) create mode 100644 docker-modules/docker-compose/Dockerfile create mode 100644 docker-modules/docker-compose/depends-on_vs_links/docker-compose-depends-on.yml create mode 100644 docker-modules/docker-compose/depends-on_vs_links/docker-compose-links.yml create mode 100644 docker-modules/docker-compose/depends-on_vs_links/docker-compose-network.yml diff --git a/docker-modules/docker-compose/Dockerfile b/docker-modules/docker-compose/Dockerfile new file mode 100644 index 0000000000..8d1bded77e --- /dev/null +++ b/docker-modules/docker-compose/Dockerfile @@ -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"] diff --git a/docker-modules/docker-compose/depends-on_vs_links/docker-compose-depends-on.yml b/docker-modules/docker-compose/depends-on_vs_links/docker-compose-depends-on.yml new file mode 100644 index 0000000000..1f9b42384e --- /dev/null +++ b/docker-modules/docker-compose/depends-on_vs_links/docker-compose-depends-on.yml @@ -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 \ No newline at end of file diff --git a/docker-modules/docker-compose/depends-on_vs_links/docker-compose-links.yml b/docker-modules/docker-compose/depends-on_vs_links/docker-compose-links.yml new file mode 100644 index 0000000000..cf84970b3c --- /dev/null +++ b/docker-modules/docker-compose/depends-on_vs_links/docker-compose-links.yml @@ -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 \ No newline at end of file diff --git a/docker-modules/docker-compose/depends-on_vs_links/docker-compose-network.yml b/docker-modules/docker-compose/depends-on_vs_links/docker-compose-network.yml new file mode 100644 index 0000000000..6b6796b43d --- /dev/null +++ b/docker-modules/docker-compose/depends-on_vs_links/docker-compose-network.yml @@ -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 diff --git a/docker-modules/docker-compose/pom.xml b/docker-modules/docker-compose/pom.xml index 7215d6e159..39bad18d02 100644 --- a/docker-modules/docker-compose/pom.xml +++ b/docker-modules/docker-compose/pom.xml @@ -34,6 +34,16 @@ org.springframework.boot spring-boot-maven-plugin + + com.baeldung.docker.app.DockAppApplication + + + + + repackage + + +