Home > Enterprise >  Docker docker compose postgresql error
Docker docker compose postgresql error

Time:10-04

I have an error connecting postgresql and app with docker compose. It seems to me that the problem lies in the fact that I connected the database via localhost(https://i.stack.imgur.com/PuthE.png). I tried to create a container based on the postgresql image, but intellij IDEA did not see the databases that I created in the container.

**The failed attempt I'm talking about **

docker run -d -port 5432:5432 --name psql-img -e POSTGRES_PASSWORD=admin postgres:13
docker exec -it psql-img bash

than I connected to the empty database that I create in psql-img container

psql -h db -p5432 -U postgres -W glerondb

File tree

https://i.stack.imgur.com/4hIa5.png

Docker file

FROM openjdk:16

ARG DIRECTORY=build/libs/*.jar
COPY $DIRECTORY gleronn.jar

ENTRYPOINT java -jar gleronn.jar

Docker compose

    version: "3.7"

services:
  gleron:
    image: igleron
    container_name: cgleron
    build: ./
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/gleron
    depends_on:
      - db
    ports:
      - "8080:8080"
  db:
    image: postgres
    environment:
      POSTGRESQL_PASSWORD: admin
      POSTGRESQL_USER: postgres
      POSTGRESQL_DB: gleron
    volumes:
    - ./pgdata:/var/lib/postgresql/data
    ports:
    - "5432:5432"

Application properties

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=admin
spring.datasource.url=jdbc:postgresql://db:5432/gleron

spring.flyway.url=jdbc:postgresql://db:5432/gleron
spring.flyway.user=postgres
spring.flyway.password=admin

spring.mail.host=smtp.mailtrap.io
spring.mail.port=2525
spring.mail.username=9fb579a8e4678b
spring.mail.password=386ea16395fa62

spring.security.oauth2.client.registration.google.client-id=1026229042300-qn7nfq0vs5ksqhbv6m9t808s1q2npcfe.apps.googleusercontent.com
spring.security.oauth2.client.registration.google.client-secret=7qcOwKK8HPM8xmXBY3tmGBjh

spring.security.oauth2.client.registration.github.client-id=e175eb2d8664fc986af8b3f8b069c405ab13ca1e
spring.security.oauth2.client.registration.github.client-secret=487f160861fd0bf4ac75

log

Starting gleronn_db_1 ... done
Creating cgleron      ... done
Attaching to gleronn_db_1, cgleron
db_1      | Error: Database is uninitialized and superuser password is not specified.
db_1      |        You must specify POSTGRES_PASSWORD to a non-empty value for the
db_1      |        superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
db_1      |
db_1      |        You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
db_1      |        connections without a password. This is *not* recommended.
db_1      |
db_1      |        See PostgreSQL documentation about "trust":
db_1      |        https://www.postgresql.org/docs/current/auth-trust.html
gleronn_db_1 exited with code 1
cgleron   | 
cgleron   |   .   ____          _            __ _ _
cgleron   |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
cgleron   | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
cgleron   |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
cgleron   |   '  |____| .__|_| |_|_| |_\__, | / / / /
cgleron   |  =========|_|==============|___/=/_/_/_/
cgleron   |  :: Spring Boot ::                (v2.5.5)
cgleron   |
cgleron   | 2021-10-03 11:33:55.792  INFO 1 --- [           main] com.sprooTex.gleronn.GleronnApplication  : Starting GleronnApplication using Java 16.0.2 on c1a8793ee951 with PID 1 (/gleronn.jar started by root in /)
cgleron   | 2021-10-03 11:33:55.795  INFO 1 --- [           main] com.sprooTex.gleronn.GleronnApplication  : No active profile set, falling back to default profiles: default
cgleron   | 2021-10-03 11:33:56.880  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
cgleron   | 2021-10-03 11:33:56.960  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 67 ms. Found 2 JPA repository interfaces.
cgleron   | 2021-10-03 11:33:57.683  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
cgleron   | 2021-10-03 11:33:57.699  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
cgleron   | 2021-10-03 11:33:57.699  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.53]
cgleron   | 2021-10-03 11:33:57.792  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
cgleron   | 2021-10-03 11:33:57.792  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1876 ms
cgleron   | 2021-10-03 11:33:57.990  INFO 1 --- [           main] o.f.c.internal.license.VersionPrinter    : Flyway Community Edition 7.7.3 by Redgate
cgleron   | 2021-10-03 11:33:58.000  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
cgleron   | 2021-10-03 11:34:09.066 ERROR 1 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.
cgleron   |
cgleron   | org.postgresql.util.PSQLException: The connection attempt failed.
cgleron   |     at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.Driver.makeConnection(Driver.java:465) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.Driver.connect(Driver.java:264) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:54) ~[flyway-core-7.7.3.jar!/:na]
cgleron   |     at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:69) ~[flyway-core-7.7.3.jar!/:na]
cgleron   |     at org.flywaydb.core.Flyway.execute(Flyway.java:508) ~[flyway-core-7.7.3.jar!/:na]
cgleron   |     at org.flywaydb.core.Flyway.migrate(Flyway.java:165) ~[flyway-core-7.7.3.jar!/:na]
cgleron   |     at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66) ~[spring-boot-autoconfigure-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at com.sprooTex.gleronn.GleronnApplication.main(GleronnApplication.java:10) ~[classes!/:na]
cgleron   |     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
cgleron   |     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
cgleron   |     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
cgleron   |     at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
cgleron   |     at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[gleronn.jar:na]
cgleron   |     at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[gleronn.jar:na]
cgleron   |     at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[gleronn.jar:na]
cgleron   |     at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[gleronn.jar:na]
cgleron   | Caused by: java.net.UnknownHostException: db
cgleron   |     at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:567) ~[na:na]
cgleron   |     at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333) ~[na:na]
cgleron   |     at java.base/java.net.Socket.connect(Socket.java:645) ~[na:na]
cgleron   |     at org.postgresql.core.PGStream.createSocket(PGStream.java:231) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.core.PGStream.<init>(PGStream.java:95) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:98) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     ... 44 common frames omitted
cgleron   |
cgleron   | 2021-10-03 11:34:09.069  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/sp
ringframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.exception.FlywaySqlException:
cgleron   | Unable to obtain connection from database: The connection attempt failed.
cgleron   | -------------------------------------------------------------------------
cgleron   | SQL State  : 08001
cgleron   | Error Code : 0
cgleron   | Message    : The connection attempt failed.
cgleron   |
cgleron   | 2021-10-03 11:34:09.073  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
cgleron   | 2021-10-03 11:34:09.093  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener :
cgleron   |
cgleron   | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
cgleron   | 2021-10-03 11:34:09.114 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed
cgleron   |
cgleron   | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.except
ion.FlywaySqlException:
cgleron   | Unable to obtain connection from database: The connection attempt failed.
cgleron   | -------------------------------------------------------------------------
cgleron   | SQL State  : 08001
cgleron   | Error Code : 0
cgleron   | Message    : The connection attempt failed.
cgleron   |
cgleron   |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.5.jar!/:2.5.5]
cgleron   |     at com.sprooTex.gleronn.GleronnApplication.main(GleronnApplication.java:10) ~[classes!/:na]
cgleron   |     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
cgleron   |     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
cgleron   |     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
cgleron   |     at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
cgleron   |     at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[gleronn.jar:na]
cgleron   |     at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[gleronn.jar:na]
cgleron   |     at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[gleronn.jar:na]
cgleron   |     at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[gleronn.jar:na]
cgleron   | Caused by: org.flywaydb.core.internal.exception.FlywaySqlException:
cgleron   | Unable to obtain connection from database: The connection attempt failed.
cgleron   | -------------------------------------------------------------------------
cgleron   | SQL State  : 08001
cgleron   | Error Code : 0
cgleron   | Message    : The connection attempt failed.
cgleron   |
cgleron   |     at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:68) ~[flyway-core-7.7.3.jar!/:na]
cgleron   |     at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:69) ~[flyway-core-7.7.3.jar!/:na]
cgleron   |     at org.flywaydb.core.Flyway.execute(Flyway.java:508) ~[flyway-core-7.7.3.jar!/:na]
cgleron   |     at org.flywaydb.core.Flyway.migrate(Flyway.java:165) ~[flyway-core-7.7.3.jar!/:na]
cgleron   |     at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66) ~[spring-boot-autoconfigure-2.5.5.jar!/:2.5.5]
cgleron   |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.10.jar!/:5.3.10]
cgleron   |     ... 26 common frames omitted
cgleron   | Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
cgleron   |     at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.Driver.makeConnection(Driver.java:465) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.Driver.connect(Driver.java:264) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar!/:na]
cgleron   |     at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:54) ~[flyway-core-7.7.3.jar!/:na]
cgleron   |     ... 32 common frames omitted
cgleron   | Caused by: java.net.UnknownHostException: db
cgleron   |     at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:567) ~[na:na]
cgleron   |     at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333) ~[na:na]
cgleron   |     at java.base/java.net.Socket.connect(Socket.java:645) ~[na:na]
cgleron   |     at org.postgresql.core.PGStream.createSocket(PGStream.java:231) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.core.PGStream.<init>(PGStream.java:95) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:98) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213) ~[postgresql-42.2.23.jar!/:42.2.23]
cgleron   |     ... 44 common frames omitted
cgleron   |
cgleron exited with code 1

CodePudding user response:

Regarding postgresql, use environment variables POSTGRES_ instead of POSTGRESQL_.

Furthermore, you can add container_name to force a name for your service container.

Otherwise it would be <directory>_<service name>_<index>

version: "3.7"

services:
  gleron:
    image: igleron
    container_name: cgleron
    build: ./
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/gleron
    depends_on:
      - db
    ports:
      - "8080:8080":
  db:
    container_name: db
    image: postgres
    environment:
      POSTGRES_PASSWORD: admin
      POSTGRES_USER: postgres
      POSTGRES_DB: gleron
    volumes:
    - ./pgdata:/var/lib/postgresql/data
    ports:
    - "5432:5432"

You can check docker-compose container states with docker-compose ps

Documentation : https://docs.docker.com/compose/reference/ps/

  • Related