Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wlad/90ecad897a2975ec4d7f40a38e8b29ab to your computer and use it in GitHub Desktop.
Save wlad/90ecad897a2975ec4d7f40a38e8b29ab to your computer and use it in GitHub Desktop.
(wlad㉿pc)-[~/…/vs/github/docker/dockerfiles]
└─$ docker build -t ehrbase/ehrbase-postgres:13.3 -f ehrbase-postgresql-db.dockerfile .
Sending build context to Docker daemon 13.31kB
Step 1/12 : FROM postgres:13.3-alpine
---> d3a70afcf848
Step 2/12 : RUN postgres -V && psql -V
---> Using cache
---> 0a07737e239e
Step 3/12 : RUN mkdir -p ${PGDATA}
---> Using cache
---> f2a1930757df
Step 4/12 : RUN chown postgres: ${PGDATA}
---> Using cache
---> 05cea4ce3fab
Step 5/12 : RUN chmod 0700 ${PGDATA}
---> Using cache
---> 2b856b89e2f5
Step 6/12 : ENV PGDATA="/var/lib/postgresql/pgdata"
---> Using cache
---> 62050ee42b50
Step 7/12 : RUN su - postgres -c "initdb -D ${PGDATA}"
---> Using cache
---> 98f815d07ef2
Step 8/12 : COPY scripts/db-setup.sql /postgres/db-setup.sql
---> cd2307ea32bc
Step 9/12 : RUN su - postgres -c "pg_ctl -D ${PGDATA} -w start" && su - postgres -c "psql < /postgres/db-setup.sql"
---> Running in 46f3f88d6fa0
waiting for server to start....2021-07-07 12:54:09.801 UTC [11] LOG: starting PostgreSQL 13.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.3.1_git20210424) 10.3.1 20210424, 64-bit
2021-07-07 12:54:09.801 UTC [11] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-07-07 12:54:09.801 UTC [11] LOG: listening on IPv6 address "::", port 5432
2021-07-07 12:54:09.809 UTC [11] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-07-07 12:54:09.818 UTC [12] LOG: database system was shut down at 2021-07-07 12:26:53 UTC
2021-07-07 12:54:09.824 UTC [11] LOG: database system is ready to accept connections
done
server started
CREATE ROLE
CREATE DATABASE
GRANT
You are now connected to database "ehrbase" as user "postgres".
CREATE SCHEMA
CREATE SCHEMA
CREATE EXTENSION
CREATE EXTENSION
ALTER DATABASE
GRANT
CREATE FUNCTION
Removing intermediate container 46f3f88d6fa0
---> 864fad7bcafe
Step 10/12 : RUN echo "host all all 0.0.0.0/0 scram-sha-256" >> ${PGDATA}/pg_hba.conf
---> Running in 6f0d58ed918e
Removing intermediate container 6f0d58ed918e
---> 459324b7cd3f
Step 11/12 : RUN echo "listen_addresses='*'" >> ${PGDATA}/postgresql.conf
---> Running in 4fa253a0257b
Removing intermediate container 4fa253a0257b
---> 21cae13f7219
Step 12/12 : EXPOSE 5432
---> Running in 23033756710e
Removing intermediate container 23033756710e
---> 1a4e1a6fb506
Successfully built 1a4e1a6fb506
Successfully tagged ehrbase/ehrbase-postgres:13.3
FROM postgres:13.3-alpine
# SHOW POSTGRES DB AND CLIENT VERSION
RUN postgres -V && \
psql -V
# # SET DEFAULT VALUES FOR DATABASE USER AND PASSWORDS
# ARG EHRBASE_USER="ehrbase"
# ARG EHRBASE_PASSWORD="ehrbase"
# ENV EHRBASE_USER=${EHRBASE_USER}
# ENV EHRBASE_PASSWORD=${EHRBASE_PASSWORD}
# CREATE CUSTOM DATA DIRECTORY AND CHANGE OWNERSHIP TO POSTGRES USER
# SET POSTGRES DATA DIRECTORY TO CUSTOM FOLDER AND INITIALIZE DB
RUN mkdir -p ${PGDATA}
RUN chown postgres: ${PGDATA}
RUN chmod 0700 ${PGDATA}
ENV PGDATA="/var/lib/postgresql/pgdata"
RUN su - postgres -c "initdb -D ${PGDATA}"
# COPY DB SETUP SCRIPT
# START DB AND LET THE SCRIPT DO ALL REQUIRED CONFIGURATION
COPY scripts/db-setup.sql /postgres/db-setup.sql
RUN su - postgres -c "pg_ctl -D ${PGDATA} -w start" && \
su - postgres -c "psql < /postgres/db-setup.sql"
# ALLOW CONNECTIONS FROM ALL ADRESSES & LISTEN TO ALL INTERFACES
RUN echo "host all all 0.0.0.0/0 scram-sha-256" >> ${PGDATA}/pg_hba.conf
RUN echo "listen_addresses='*'" >> ${PGDATA}/postgresql.conf
EXPOSE 5432
@wlad
Copy link
Author

wlad commented Jul 7, 2021

Output of EHRbase docker container trying to start using above PostgresQSL DB

docker run --name ehrdb \
                   --network ehrnet \
                   -d -p 5432:5432 \
                   ehrbase/ehrbase-postgres:13.3

docker run --name ehrdocker \
                   --network ehrnet \
                   -e DB_URL=jdbc:postgresql://ehrdb:5432/ehrbase \
                   -e DB_USER=ehrbase \
                   -e DB_PASS=ehrbase \
                   -p 8080:8080 \
                   ehrbase/ehrbase:13.3

EHRBASE_VERSION: 0.16.5

 ______ _    _ _____  _
|  ____| |  | |  __ \| |
| |__  | |__| | |__) | |__   __ _ ___  ___
|  __| |  __  |  _  /| '_ \ / _` / __|/ _ \
| |____| |  | | | \ \| |_) | (_| \__ \  __/
|______|_|  |_|_|  \_\_.__/ \__,_|___/\___|
Spring Boot 2.3.5.RELEASE
EHRbase  (v0.16.5)
https://ehrbase.org/ 
2021-07-07 13:04:21.153  INFO 9 --- [           main] org.ehrbase.application.EhrBase          : Starting EhrBase v0.16.5 on 07f637b46f39 with PID 9 (/ehrbase.jar started by root in /)
2021-07-07 13:04:21.155  INFO 9 --- [           main] org.ehrbase.application.EhrBase          : The following profiles are active: docker
2021-07-07 13:04:22.244  INFO 9 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2021-07-07 13:04:22.266  INFO 9 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14ms. Found 0 JPA repository interfaces.
2021-07-07 13:04:22.764  INFO 9 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-07-07 13:04:22.774  INFO 9 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-07-07 13:04:22.774  INFO 9 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.39]
2021-07-07 13:04:22.847  INFO 9 --- [           main] o.a.c.c.C.[.[localhost].[/ehrbase]       : Initializing Spring embedded WebApplicationContext
2021-07-07 13:04:22.847  INFO 9 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1649 ms
2021-07-07 13:04:23.085  INFO 9 --- [           main] o.f.c.internal.license.VersionPrinter    : Flyway Community Edition 6.5.7 by Redgate
2021-07-07 13:04:23.093  INFO 9 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-07-07 13:04:24.204 ERROR 9 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

org.postgresql.util.PSQLException: FATAL: password authentication failed for user "ehrbase"
        at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:613)
        at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:161)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:225)
        at org.postgresql.Driver.makeConnection(Driver.java:465)
        at org.postgresql.Driver.connect(Driver.java:264)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358)
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
        at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56)
        at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:80)
        at org.flywaydb.core.Flyway.execute(Flyway.java:453)
        at org.flywaydb.core.Flyway.migrate(Flyway.java:158)
        at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:311)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
        at org.ehrbase.application.EhrBase.main(EhrBase.java:36)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)

2021-07-07 13:04:24.206  WARN 9 --- [           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/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.exception.FlywaySqlException: 
Unable to obtain connection from database: FATAL: password authentication failed for user "ehrbase"
---------------------------------------------------------------------------------------------------
SQL State  : 28P01
Error Code : 0
Message    : FATAL: password authentication failed for user "ehrbase"

2021-07-07 13:04:24.209  INFO 9 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-07-07 13:04:24.222  INFO 9 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-07 13:04:24.223 ERROR 9 --- [           main] o.s.boot.SpringApplication               : Application run failed

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.exception.FlywaySqlException: 
Unable to obtain connection from database: FATAL: password authentication failed for user "ehrbase"
---------------------------------------------------------------------------------------------------
SQL State  : 28P01
Error Code : 0
Message    : FATAL: password authentication failed for user "ehrbase"

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:311)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
        at org.ehrbase.application.EhrBase.main(EhrBase.java:36)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: org.flywaydb.core.internal.exception.FlywaySqlException: 
Unable to obtain connection from database: FATAL: password authentication failed for user "ehrbase"
---------------------------------------------------------------------------------------------------
SQL State  : 28P01
Error Code : 0
Message    : FATAL: password authentication failed for user "ehrbase"

        at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:65)
        at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:80)
        at org.flywaydb.core.Flyway.execute(Flyway.java:453)
        at org.flywaydb.core.Flyway.migrate(Flyway.java:158)
        at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790)
        ... 27 common frames omitted
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "ehrbase"
        at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:613)
        at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:161)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:225)
        at org.postgresql.Driver.makeConnection(Driver.java:465)
        at org.postgresql.Driver.connect(Driver.java:264)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358)
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
        at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56)
        ... 33 common frames omitted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment