При первом запуске dcoker-compose появляется ошибка liqubase, но со второго запуска приложение запускается без ошибок
При первом запуске docker-compose up --build приложение падает со следующей ошибкой
Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: org.postgresql.util.PSQLException: The connection attempt failed.
Но при втором запуске, приложение запускается нормально
Мой docker-compose :
version: '3.8'
services:
client-backend:
image: notes:0.0.1
build:
context: .
dockerfile: Dockerfile
ports:
- "8085:8085"
depends_on:
- postgres
environment:
- SERVER_PORT= 8085
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgres/notes_bd
postgres:
image: 'postgres:14.1'
ports:
- 5432:5432
environment:
- 'POSTGRES_USER=postgres'
- 'POSTGRES_PASSWORD=1234'
- 'POSTGRES_DB=notes_bd'
volumes:
- ./infrastructure/db/drop_db.sql:/docker-entrypoint-initdb.d/drop_db.sql
- ./infrastructure/db/create_db.sql:/docker-entrypoint-initdb.d/create_db.sql
Полный лог запуска с ошибкой:
Network notes_default Created 0.1s
✔ Container notes-postgres-1 Created 0.8s
✔ Container notes-client-backend-1 Created 1.8s
Attaching to client-backend-1, postgres-1
postgres-1 | The files belonging to this database system will be owned by user "postgres".
postgres-1 | This user must also own the server process.
postgres-1 |
postgres-1 | The database cluster will be initialized with locale "en_US.utf8".
postgres-1 | The default database encoding has accordingly been set to "UTF8".
postgres-1 | The default text search configuration will be set to "english".
postgres-1 |
postgres-1 | Data page checksums are disabled.
postgres-1 |
postgres-1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgres-1 | creating subdirectories ... ok
postgres-1 | selecting dynamic shared memory implementation ... posix
postgres-1 | selecting default max_connections ... 100
postgres-1 | selecting default shared_buffers ... 128MB
postgres-1 | selecting default time zone ... Etc/UTC
postgres-1 | creating configuration files ... ok
postgres-1 | running bootstrap script ... ok
postgres-1 | performing post-bootstrap initialization ... ok
postgres-1 | syncing data to disk ... ok
postgres-1 |
postgres-1 |
postgres-1 | Success. You can now start the database server using:
postgres-1 |
postgres-1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
postgres-1 |
postgres-1 | initdb: warning: enabling "trust" authentication for local connections
postgres-1 | You can change this by editing pg_hba.conf or using the option -A, or
postgres-1 | --auth-local and --auth-host, the next time you run initdb.
postgres-1 | waiting for server to start....2024-02-13 13:02:26.726 UTC [48] LOG: starting PostgreSQL 14.1 (Debian 14.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgres-1 | 2024-02-13 13:02:26.730 UTC [48] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres-1 | 2024-02-13 13:02:26.870 UTC [49] LOG: database system was shut down at 2024-02-13 13:02:23 UTC
postgres-1 | 2024-02-13 13:02:26.893 UTC [48] LOG: database system is ready to accept connections
postgres-1 | done
postgres-1 | server started
postgres-1 | CREATE DATABASE
postgres-1 |
postgres-1 |
postgres-1 | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/create_db.sql
postgres-1 | psql:/docker-entrypoint-initdb.d/create_db.sql: error: could not read from input file: Is a directory
postgres-1 exited with code 1
client-backend-1 |
client-backend-1 | . ____ _ __ _ _
client-backend-1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
client-backend-1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
client-backend-1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
client-backend-1 | ' |____| .__|_| |_|_| |_\__, | / / / /
client-backend-1 | =========|_|==============|___/=/_/_/_/
client-backend-1 | :: Spring Boot :: (v3.2.2)
client-backend-1 |
client-backend-1 | 2024-02-13T13:02:31.142Z INFO 1 --- [ main] c.danillkucheruk.notes.NotesApplication : Starting NotesApplication v0.0.1-SNAPSHOT using Java 17.0.10 with PID 1 (/app/*.jar started by root in /app)
client-backend-1 | 2024-02-13T13:02:31.175Z INFO 1 --- [ main] c.danillkucheruk.notes.NotesApplication : No active profile set, falling back to 1 default profile: "default"
client-backend-1 | 2024-02-13T13:02:42.206Z INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
client-backend-1 | 2024-02-13T13:02:42.620Z INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 374 ms. Found 3 JPA repository interfaces.
client-backend-1 | 2024-02-13T13:02:47.997Z INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8085 (http)
client-backend-1 | 2024-02-13T13:02:48.095Z INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
client-backend-1 | 2024-02-13T13:02:48.096Z INFO 1 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.18]
client-backend-1 | 2024-02-13T13:02:48.396Z INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
client-backend-1 | 2024-02-13T13:02:48.400Z INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 16224 ms
client-backend-1 | 2024-02-13T13:02:55.024Z WARN 1 --- [ main] ConfigServletWebServerApplicationContext : 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]: org.postgresql.util.PSQLException: The connection attempt failed.
client-backend-1 | 2024-02-13T13:02:55.042Z INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
client-backend-1 | 2024-02-13T13:02:55.220Z INFO 1 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
client-backend-1 |
client-backend-1 | Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
client-backend-1 | 2024-02-13T13:02:55.370Z ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
client-backend-1 |
client-backend-1 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: org.postgresql.util.PSQLException: The connection attempt failed.
client-backend-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773) ~[spring-beans-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599) ~[spring-beans-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[spring-beans-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[spring-beans-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:312) ~[spring-beans-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1231) ~[spring-context-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:949) ~[spring-context-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624) ~[spring-context-6.1.3.jar!/:6.1.3]
client-backend-1 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.2.jar!/:3.2.2]