I want to create a docker-compose with backend: Spring Boot, frontend: Angular, and Postgresql DB. I tried everything on the internet, but it's not working. It's connecting and after a few seconds it says connection refused
My Docker-Compose:
version: '3'
services:
database:
image: postgres:13.3
container_name: database
environment:
POSTGRES_DB: "fahrzeuge_verwalten"
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
ports:
- 5432:5432
networks:
- backendNetwork
springapi:
image: openjdk:11-jre-slim
container_name: springapi
ports:
- 8080:8080
depends_on:
- database
volumes:
- ./target/fahrzeugverwaltung-0.0.1-SNAPSHOT.jar:/app.jar
command: ["java", "-jar", "app.jar"]
networks:
- backendNetwork
- frontendNetwork
angular:
image: nginx:alpine
container_name: angular
ports:
- 4200:80
depends_on:
- springapi
volumes:
- ./nginx.conf:/Users/betu/Documents/Docker-Compose/nginx.conf
- ./carManagement/dist/carManagement/:/usr/share/nginx/html
networks:
- frontendNetwork
volumes:
fahrzeugverwaltungData:
networks:
backendNetwork:
frontendNetwork:
Application Properties:
spring.datasource.url= jdbc:postgresql://database:5432/fahrzeuge_verwalten
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.hibernate.ddl-auto=validate
spring.liquibase.change-log=classpath:db.changelog/changelog-master.yaml
And the Message:
C:\Users\betu\Documents\Git-
Proj\fahrzeug_verwaltung\fahrzeugverwaltung\src\main\resources\db.changelog>docker-compose up
Creating network "fahrzeugverwaltung_backendNetwork" with the default driver
Creating network "fahrzeugverwaltung_frontendNetwork" with the default driver
Creating database ... done
Creating springapi ... done
Creating angular ... done
Attaching to database, springapi, angular
angular | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to
perform configuration
angular | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
angular | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-
default.sh
angular | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of
/etc/nginx/conf.d/default.conf
database | The files belonging to this database system will be owned by user "postgres".
database | This user must also own the server process.
database |
database | The database cluster will be initialized with locale "en_US.utf8".
database | The default database encoding has accordingly been set to "UTF8".
database | The default text search configuration will be set to "english".
database |
database | Data page checksums are disabled.
database |
database | fixing permissions on existing directory /var/lib/postgresql/data ... ok
database | creating subdirectories ... ok
database | selecting dynamic shared memory implementation ... posix
database | selecting default max_connections ... 100
database | selecting default shared_buffers ... 128MB
database | selecting default time zone ... Etc/UTC
database | creating configuration files ... ok
database | running bootstrap script ... ok
database | performing post-bootstrap initialization ... ok
database | syncing data to disk ... ok
database |
database |
database | Success. You can now start the database server using:
database |
database | pg_ctl -D /var/lib/postgresql/data -l logfile start
database |
database | initdb: warning: enabling "trust" authentication for local connections
database | You can change this by editing pg_hba.conf or using the option -A, or
database | --auth-local and --auth-host, the next time you run initdb.
database | waiting for server to start....2021-07-09 16:13:08.180 UTC [48] LOG: starting
PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-lin
ux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
database | 2021-07-09 16:13:08.184 UTC [48] LOG: listening on Unix socket
"/var/run/postgresql/.s.PGSQL.5432"
database | 2021-07-09 16:13:08.194 UTC [49] LOG: database system was shut down at 2021-
07-09 16:13:07 UTC
database | 2021-07-09 16:13:08.199 UTC [48] LOG: database system is ready to accept
connections
database | done
database | server started
database | CREATE DATABASE
database |
database |
database | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
database |
database | 2021-07-09 16:13:08.460 UTC [48] LOG: received fast shutdown request
database | waiting for server to shut down....2021-07-09 16:13:08.463 UTC [48] LOG:
aborting any active transactions
database | 2021-07-09 16:13:08.464 UTC [48] LOG: background worker "logical replication
launcher" (PID 55) exited with exit code 1
database | 2021-07-09 16:13:08.464 UTC [50] LOG: shutting down
database | 2021-07-09 16:13:08.481 UTC [48] LOG: database system is shut down
database | done
database | server stopped
database |
database | PostgreSQL init process complete; ready for start up.
database |
database | 2021-07-09 16:13:08.599 UTC [1] LOG: starting PostgreSQL 13.3 (Debian 13.3-
1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian
8.3.0-6) 8.3.0, 64-bit
database | 2021-07-09 16:13:08.599 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port
5432
angular | 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in
/etc/nginx/conf.d/default.conf
database | 2021-07-09 16:13:08.599 UTC [1] LOG: listening on IPv6 address "::", port 5432
database | 2021-07-09 16:13:08.608 UTC [1] LOG: listening on Unix socket
"/var/run/postgresql/.s.PGSQL.5432"
database | 2021-07-09 16:13:08.619 UTC [76] LOG: database system was shut down at 2021-
07-09 16:13:08 UTC
database | 2021-07-09 16:13:08.624 UTC [1] LOG: database system is ready to accept
connections
angular | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-
templates.sh
angular | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-
processes.sh
angular | /docker-entrypoint.sh: Configuration complete; ready for start up
angular | 2021/07/09 16:13:11 [notice] 1#1: using the "epoll" event method
angular | 2021/07/09 16:13:11 [notice] 1#1: nginx/1.21.1
angular | 2021/07/09 16:13:11 [notice] 1#1: built by gcc 10.3.1 20210424 (Alpine
10.3.1_git20210424)
angular | 2021/07/09 16:13:11 [notice] 1#1: OS: Linux 5.4.72-microsoft-standard-WSL2
angular | 2021/07/09 16:13:11 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
angular | 2021/07/09 16:13:11 [notice] 1#1: start worker processes
angular | 2021/07/09 16:13:11 [notice] 1#1: start worker process 33
angular | 2021/07/09 16:13:11 [notice] 1#1: start worker process 34
angular | 2021/07/09 16:13:11 [notice] 1#1: start worker process 35
angular | 2021/07/09 16:13:11 [notice] 1#1: start worker process 36
angular | 2021/07/09 16:13:11 [notice] 1#1: start worker process 37
angular | 2021/07/09 16:13:11 [notice] 1#1: start worker process 38
angular | 2021/07/09 16:13:11 [notice] 1#1: start worker process 39
angular | 2021/07/09 16:13:11 [notice] 1#1: start worker process 40
springapi |
springapi | . ____ _ __ _ _
springapi | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
springapi | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
springapi | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
springapi | ' |____| .__|_| |_|_| |_\__, | / / / /
springapi | =========|_|==============|___/=/_/_/_/
springapi | :: Spring Boot :: (v2.5.1)
springapi |
springapi | HV000001: Hibernate Validator 6.2.0.Final
springapi | Starting FahrzeugverwaltungApplication v0.0.1-SNAPSHOT using Java 11.0.11 on
ae616c1ba89f with PID 1 (/app.jar started by root in /)
springapi | No active profile set, falling back to default profiles: default
springapi | Bootstrapping Spring Data JPA repositories in DEFAULT mode.
springapi | Finished Spring Data repository scanning in 369 ms. Found 1 JPA repository
interfaces.
springapi | Tomcat initialized with port(s): 8080 (http)
springapi | Initializing ProtocolHandler ["http-nio-8080"]
springapi | Starting service [Tomcat]
springapi | Starting Servlet engine: [Apache Tomcat/9.0.46]
springapi | Initializing Spring embedded WebApplicationContext
springapi | Root WebApplicationContext: initialization completed in 7452 ms
angular | 2021/07/09 16:13:22 [error] 33#33: *1 directory index of
"/usr/share/nginx/html/" is forbidden, client: 192.168.32.1, server: localhost,
request: "GET / HTTP/1.1", host: "localhost:4200"
angular | 192.168.32.1 - - [09/Jul/2021:16:13:22 +0000] "GET / HTTP/1.1" 403 555 "-"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" "-"
springapi | HikariPool-1 - Starting...
springapi | HikariPool-1 - Exception during pool initialization.
springapi | org.postgresql.util.PSQLException: Connection to 127.0.0.1:5432 refused. Check
that the hostname and port are correct and that the postma
ster is accepting TCP/IP connections.
springapi | at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(
ConnectionFactoryImpl.java:303)
springapi | at
org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
springapi | at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)
springapi | at org.postgresql.Driver.makeConnection(Driver.java:465)
springapi | at org.postgresql.Driver.connect(Driver.java:264)
springapi | at
com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
springapi | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
springapi | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
springapi | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476)
springapi | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
springapi | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
springapi | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
springapi | at
liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:272)
springapi | at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
invokeInitMethods(AbstractAutowireCapableBeanFactory.jav
a:1845)
springapi | at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(
AbstractAutowireCapableBeanFactory.java:1
782)
springapi | at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(
AbstractAutowireCapableBeanFactory.java:602)
springapi | at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(
AbstractAutowireCapableBeanFactory.java:524)
springapi | at
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(
AbstractBeanFactory.java:335)
springapi | at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(
DefaultSingletonBeanRegistry.java:234)
springapi | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(
AbstractBeanFactory.java:333)
springapi | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
AbstractBeanFactory.java:208)
springapi | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(
AbstractBeanFactory.java:322)
springapi | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
AbstractBeanFactory.java:208)
springapi | at org.springframework.context.support.AbstractApplicationContext.getBean(
AbstractApplicationContext.java:1154)
springapi | at
org.springframework.context.support.AbstractApplicationContext.
finishBeanFactoryInitialization(AbstractApplicationContext.java:908)
springapi | at
org.springframework.context.support.AbstractApplicationContext.refresh
(AbstractApplicationContext.java:583)
springapi | at
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(
ServletWebServerApplicationContext.java:145)
springapi | at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
springapi | at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
springapi | at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
springapi | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
springapi | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)
springapi | at com.webapp.fahrzeugverwaltung.FahrzeugverwaltungApplication.main(
FahrzeugverwaltungApplication.java:10)
springapi | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
springapi | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown
Source)
springapi | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
springapi | at java.base/java.lang.reflect.Method.invoke(Unknown Source)
springapi | at
org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
springapi | at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
springapi | at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
springapi | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
springapi | Caused by: java.net.ConnectException: Connection refused (Connection refused)
springapi | at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
springapi | at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
springapi | at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
springapi | at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
springapi | at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
springapi | at java.base/java.net.Socket.connect(Unknown Source)
springapi | at org.postgresql.core.PGStream.createSocket(PGStream.java:231)
springapi | at org.postgresql.core.PGStream.<init>(PGStream.java:95)
springapi | at
org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:98)
springapi | at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(
ConnectionFactoryImpl.java:213)
springapi | ... 40 common frames omitted
springapi | Exception encountered during context initialization - cancelling refresh
attempt: org.springframework.beans.factory.BeanCreationException
: Error creating bean with name 'liquibase' defined in class path resource
[org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$
LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is
liquibase.exception.DatabaseException: org.postgresql.util.PSQLExce
ption: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct
and that the postmaster is accepting TCP/IP connections.
springapi | Stopping service [Tomcat]
springapi |
springapi |
springapi | Error starting ApplicationContext. To display the conditions report re-run your
application with 'debug' enabled.
springapi | Application run failed
springapi | org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'liquibase' defined in class path resource [org/sp
ringframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$
LiquibaseConfiguration.class]: Invocation of init method failed; nested exception
is liquibase.exception.DatabaseException: org.postgresql.util.PSQLException: Connection to
127.0.0.1:5432 refused. Check that the hostname and port are
correct and that the postmaster is accepting TCP/IP connections.
springapi | at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
initializeBean(AbstractAutowireCapableBeanFactory.java:1 786)
springapi | at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
doCreateBean(AbstractAutowireCapableBeanFactory.java:602 )
springapi | at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
createBean(AbstractAutowireCapableBeanFactory.java:524)
springapi | at
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(
AbstractBeanFactory.java:335)
springapi | at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(
DefaultSingletonBeanRegistry.java:234)
springapi | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(
AbstractBeanFactory.java:333)
springapi | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
AbstractBeanFactory.java:208)
springapi | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(
AbstractBeanFactory.java:322)
springapi | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
AbstractBeanFactory.java:208)
springapi | at org.springframework.context.support.AbstractApplicationContext.getBean(
AbstractApplicationContext.java:1154)
springapi | at org.springframework.context.support.AbstractApplicationContext.
finishBeanFactoryInitialization(AbstractApplicationContext.java:908)
springapi | at org.springframework.context.support.AbstractApplicationContext.refresh(
AbstractApplicationContext.java:583)
springapi | at
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.
refresh(ServletWebServerApplicationContext.java:145)
springapi | at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
springapi | at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
springapi | at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
springapi | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
springapi | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)
springapi | at com.webapp.fahrzeugverwaltung.FahrzeugverwaltungApplication.main(
FahrzeugverwaltungApplication.java:10)
springapi | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
springapi | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown
Source)
springapi | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
springapi | at java.base/java.lang.reflect.Method.invoke(Unknown Source)
springapi | at
org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
springapi | at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
springapi | at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
springapi | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
springapi | Caused by: liquibase.exception.DatabaseException:
org.postgresql.util.PSQLException: Connection to 127.0.0.1:5432 refused. Check that the
hostname and port are correct and that the postmaster is accepting TCP/IP connections.
springapi | at
liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:277)
springapi | at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.
invokeInitMethods(AbstractAutowireCapableBeanFactory.jav
a:1845)
springapi | at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(
AbstractAutowireCapableBeanFactory.java:1 782)
springapi | ... 26 common frames omitted
springapi | Caused by: org.postgresql.util.PSQLException: Connection to 127.0.0.1:5432
refused. Check that the hostname and port are correct and that
the postmaster is accepting TCP/IP connections.
springapi | at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(
ConnectionFactoryImpl.java:303)
springapi | at
org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
springapi | at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)
springapi | at org.postgresql.Driver.makeConnection(Driver.java:465)
springapi | at org.postgresql.Driver.connect(Driver.java:264)
springapi | at
com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
springapi | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
springapi | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
springapi | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476)
springapi | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
springapi | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
springapi | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
springapi | at
liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:272)
springapi | ... 28 common frames omitted
springapi | Caused by: java.net.ConnectException: Connection refused (Connection refused)
springapi | at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
springapi | at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
springapi | at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
springapi | at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
springapi | at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
springapi | at java.base/java.net.Socket.connect(Unknown Source)
springapi | at org.postgresql.core.PGStream.createSocket(PGStream.java:231)
springapi | at org.postgresql.core.PGStream.<init>(PGStream.java:95)
springapi | at
org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:98)
springapi | at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(
ConnectionFactoryImpl.java:213)
springapi | ... 40 common frames omitted
springapi exited with code 1
I'm a beginner, so can anybody please help me with this problem?