I'm trying to run a Micronaut service that uses PostgreSQL on a docker-compose file. But I'm having the following issue:
21:12:32.741 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
21:12:33.744 [main] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
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.<init>(HikariDataSource.java:81)
at io.micronaut.configuration.jdbc.hikari.HikariUrlDataSource.<init>(HikariUrlDataSource.java:35)
at io.micronaut.configuration.jdbc.hikari.DatasourceFactory.dataSource(DatasourceFactory.java:66)
at io.micronaut.configuration.jdbc.hikari.$DatasourceFactory$DataSource0Definition.build(Unknown Source)
at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:153)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1979)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2768)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2754)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2425)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2399)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1264)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1014)
at io.micronaut.configuration.hibernate.jpa.$EntityManagerFactoryBean$HibernateStandardServiceRegistry0Definition.doBuild(Unknown Source)
at io.micronaut.context.AbstractParametrizedBeanDefinition.build(AbstractParametrizedBeanDefinition.java:118)
at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:149)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1979)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2768)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2754)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2425)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2399)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1264)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1014)
at io.micronaut.configuration.hibernate.jpa.$EntityManagerFactoryBean$HibernateMetadataSources1Definition.doBuild(Unknown Source)
at io.micronaut.context.AbstractParametrizedBeanDefinition.build(AbstractParametrizedBeanDefinition.java:118)
at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:149)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1979)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2768)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2754)
at io.micronaut.context.DefaultBeanContext.loadContextScopeBean(DefaultBeanContext.java:2292)
at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1562)
at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:234)
at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:2905)
at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:231)
at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:180)
at io.micronaut.runtime.Micronaut.start(Micronaut.java:71)
at org.wcode.author.service.ApplicationKt.main(Application.kt:10)
Caused by: java.net.UnknownHostException: st-database
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:220)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:609)
at org.postgresql.core.PGStream.createSocket(PGStream.java:231)
at org.postgresql.core.PGStream.<init>(PGStream.java:95)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:98)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
... 46 common frames omitted
Files definition
Following is the definition of the files that I'm using on my current project.
docker-compose.yml
version: '3.8'
services:
st-author-service:
image: author-service:latest
environment:
- JDBC_URL=jdbc:postgresql://st-database:5432/sentency_db
- JDBC_USER=<USERNAME>
- JDBC_PASSWORD=<PASSWORD>
- JDBC_DRIVER=org.postgresql.Driver
depends_on:
- st-database
networks:
- database-network
- internal
st-database:
image: postgres:13.3-alpine
restart: always
env_file:
- database.env # configure postgres
volumes:
- database-data:/var/lib/postgresql/data/
networks:
- database-network
volumes:
database-data:
networks:
database-network:
driver: bridge
external: false
internal:
application.yml
micronaut:
application:
name: authorService
server:
port: 7000
datasources:
default:
url: ${JDBC_URL:`jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE`}
username: ${JDBC_USER:sa}
password: ${JDBC_PASSWORD:""}
driverClassName: ${JDBC_DRIVER:org.h2.Driver}
schema-generate: CREATE_DROP
jpa:
default:
entity-scan:
packages: 'org.wcode.author.service.domain.entities'
properties:
hibernate:
hbm2ddl:
auto: update
show_sql: true
Tests
I tested the application.yml pointing to a PostgreSQL database deployed on Docker and it worked, the problem started when I tried to use docker-compose to structure the deployment. To check if the network definition was working I deployed pgAdmin together with that configuration and I was able to connect to the database.
After that specific line:
Caused by: java.net.UnknownHostException: st-database
I come to the conclusion that the issue was caused by the host not being found.
I already made a lot of research and haven't found a way to solve that problem. I can't see what I'm missing.
Thanks in advance for all the help.
Update
I was able to get the connection log from the PostgreSQL container and only pgAdmin connection is appearing, the service is not even reaching the container to connect. The network being used is the same. Here is the log:
2021-08-10 15:43:13.465 GMT [100] LOG: connection received: host=sentency-deploy_pgAdmin_1.sentency-deploy_database-network port=40848
2021-08-10 15:43:13.466 GMT [100] LOG: connection authorized: user=user database=postgres
2021-08-10 15:43:13.478 GMT [101] LOG: connection received: host=sentency-deploy_pgAdmin_1.sentency-deploy_database-network port=40850
2021-08-10 15:43:13.479 GMT [101] LOG: connection authorized: user=user database=sentency_db
2021-08-10 15:43:13.491 GMT [102] LOG: connection received: host=sentency-deploy_pgAdmin_1.sentency-deploy_database-network port=40852
2021-08-10 15:43:13.493 GMT [102] LOG: connection authorized: user=user database=postgres
2021-08-10 15:43:17.750 GMT [103] LOG: connection received: host=sentency-deploy_pgAdmin_1.sentency-deploy_database-network port=40858
Now I think the problem could be the way I'm building the image. My current Dockerfile is:
FROM ghcr.io/graalvm/graalvm-ce:ol7-java11-21.2.0 as build
WORKDIR /author-service
COPY . /author-service
RUN yum install -y -q xz
RUN curl -sL -o - https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz | tar xJ
RUN gu install native-image
RUN ./gradlew assemble
RUN native-image --no-fallback --static -jar /author-service/build/libs/author-service-*-all.jar service
RUN ./upx-3.96-amd64_linux/upx -7 /author-service/service
FROM scratch
EXPOSE 7000:7000
COPY --from=build /author-service/service /service
ENTRYPOINT ["./service"]
That's giving me an image of 27.67MB.
From the docker compose documentation: depends_on does not wait for [st-database] to be “ready”. So maybe this is caused by the Postgres database not being ready to accept connections at the time your app tries to. The UnknownHostException is a bit strange in that case but that may depend on when docker is binding the port. To fix the problem you would need to write a script that waits for readiness as in the second example here.
Related
I am currently struggling to connect to a locally created postgres db. The postgres server is defined inside a docker-compose.yml like this:
version: '3.9'
services:
postgres:
image: bitnami/postgresql:13.4.0
container_name: mopla-postgres
restart: always
environment:
- POSTGRES_USER=mopla
- POSTGRES_PASSWORD=develop
- POSTGRESQL_DATABASE=mopla
volumes:
- mopla-postgres:/bitnami/postgresql
- ./database_dumps:/docker-entrypoint-initdb.d
ports:
- 5432:5432
...
The container seems to start:
postgresql 09:02:41.34
postgresql 09:02:41.34 Welcome to the Bitnami postgresql container
postgresql 09:02:41.34 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
postgresql 09:02:41.34 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
postgresql 09:02:41.35
postgresql 09:02:41.36 INFO ==> ** Starting PostgreSQL setup **
postgresql 09:02:41.39 INFO ==> Validating settings in POSTGRESQL_* env vars..
postgresql 09:02:41.39 INFO ==> Loading custom pre-init scripts...
postgresql 09:02:41.40 INFO ==> Initializing PostgreSQL database...
postgresql 09:02:41.42 INFO ==> pg_hba.conf file not detected. Generating it...
postgresql 09:02:41.42 INFO ==> Generating local authentication configuration
postgresql 09:02:41.43 INFO ==> Deploying PostgreSQL with persisted data...
postgresql 09:02:41.43 INFO ==> Configuring replication parameters
postgresql 09:02:41.46 INFO ==> Configuring fsync
postgresql 09:02:41.49 INFO ==> Loading custom scripts...
postgresql 09:02:41.50 INFO ==> Enabling remote connections
postgresql 09:02:41.51 INFO ==> ** PostgreSQL setup finished! **
postgresql 09:02:41.55 INFO ==> ** Starting PostgreSQL **
2022-11-28 09:02:41.571 GMT [1] LOG: pgaudit extension initialized
2022-11-28 09:02:41.576 GMT [1] LOG: starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2022-11-28 09:02:41.576 GMT [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-11-28 09:02:41.576 GMT [1] LOG: listening on IPv6 address "::", port 5432
2022-11-28 09:02:41.580 GMT [1] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2022-11-28 09:02:41.586 GMT [85] LOG: database system was shut down at 2022-11-28 09:02:36 GMT
2022-11-28 09:02:41.590 GMT [1] LOG: database system is ready to accept connections
Now, when I try to connect to this database with pgadmin with the password "develop", I get an authentication error:
Here is the configuration:
Is there anything obvious I am doing wrong? Anything I can do to debug this issue further?
Alright, I figured it out.
There was a windows-service running that was also opening a postgres db on the same port (5432), so I was trying to connect to the wrong db.
TCPView helped me figuring out the issue.
I am not quite sure where my problem is, I can only describe some symtoms, so please be patient with error logs/configurations.
I want to install a HA postgresql database. The easiest ways to me seems to do it via preconfigured docker images.
I am using the bitnami postgresql image for this with the following configuration in swarm mode on two separate nodes.
version: '3.8'
services:
postgresql-master:
image: 'docker.io/bitnami/postgresql:15'
ports:
- '5432:5432'
networks:
- postgres_network
volumes:
- '/localVol:/bitnami/postgresql'
environment:
- POSTGRESQL_REPLICATION_MODE=master
- POSTGRESQL_REPLICATION_USER=repmgr_username
- POSTGRESQL_REPLICATION_PASSWORD=repmgr_password
- POSTGRESQL_USERNAME=username
- POSTGRESQL_PASSWORD=password
- POSTGRESQL_DATABASE=dbname
- POSTGRESQL_SYNCHRONOUS_COMMIT_MODE=on
- POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS=1
deploy:
placement:
constraints:
- node.labels.type == primary
postgresql-slave:
image: 'docker.io/bitnami/postgresql:15'
ports:
- '5432'
networks:
- postgres_network
depends_on:
- postgresql-master
environment:
- POSTGRESQL_USERNAME=username
- POSTGRESQL_PASSWORD=password
- POSTGRESQL_REPLICATION_MODE=slave
- POSTGRESQL_REPLICATION_USER=repmgr_username
- POSTGRESQL_REPLICATION_PASSWORD=repmgr_password
- POSTGRESQL_MASTER_HOST=postgresql-master
- POSTGRESQL_MASTER_PORT_NUMBER=5432
volumes:
- '/localVol:/bitnami/postgresql'
deploy:
placement:
constraints:
- node.labels.type != primary
networks:
postgres_network:
driver: overlay
external: false
internal: true
ipam:
config:
- subnet: 10.70.1.0/24
The swarm is created via a simple init command and the node is joined via the join command. No extra config.
When running this file with docker compose up (without the deploy constraints) on one host, the two containers are up and running, replicating the database and so on. Working as desired.
When running this file as is with docker stack up, the primary is running and stable, the secondary is not; see logs
Primary
postgresql 14:07:57.00 INFO ==> ** Starting PostgreSQL setup **
postgresql 14:07:57.06 INFO ==> Validating settings in POSTGRESQL_* env vars..
postgresql 14:07:57.07 INFO ==> Loading custom pre-init scripts...
postgresql 14:07:57.09 INFO ==> Initializing PostgreSQL database...
postgresql 14:07:57.10 INFO ==> Custom configuration /opt/bitnami/postgresql/conf/pg_hba.conf detected
postgresql 14:07:57.17 INFO ==> Deploying PostgreSQL with persisted data...
postgresql 14:07:57.21 INFO ==> Configuring replication parameters
postgresql 14:07:57.28 INFO ==> Configuring fsync
postgresql 14:07:57.31 INFO ==> Loading custom scripts...
postgresql 14:07:57.31 INFO ==> Enabling remote connections
postgresql 14:07:57.33 INFO ==> ** PostgreSQL setup finished! **
postgresql 14:07:57.34 INFO ==> ** Starting PostgreSQL **
2022-11-16 14:07:57.363 GMT [1] LOG: pgaudit extension initialized
2022-11-16 14:07:57.374 GMT [1] LOG: starting PostgreSQL 15.0 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-11-16 14:07:57.377 GMT [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-11-16 14:07:57.378 GMT [1] LOG: could not create IPv6 socket for address "::": Address family not supported by protocol
2022-11-16 14:07:57.380 GMT [1] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2022-11-16 14:07:57.384 GMT [83] LOG: database system was shut down at 2022-11-16 14:07:36 GMT
2022-11-16 14:07:57.392 GMT [1] LOG: database system is ready to accept connections
secondary
postgresql 14:40:51.58 INFO ==> ** Starting PostgreSQL setup **
postgresql 14:40:51.64 INFO ==> Validating settings in POSTGRESQL_* env vars..
postgresql 14:40:51.65 INFO ==> Loading custom pre-init scripts...
postgresql 14:40:51.66 INFO ==> Initializing PostgreSQL database...
postgresql 14:40:51.70 INFO ==> pg_hba.conf file not detected. Generating it...
postgresql 14:40:51.70 INFO ==> Generating local authentication configuration
postgresql 14:40:51.74 INFO ==> Waiting for replication master to accept connections (60 timeout)...
postgresql-master:5432 - no response
The secondary restarts itself after a time of constantly logging no response.
I have tried pinging the containers which works. Also when exposing the port of the primary to the host, it is possible to access the database from the host BUT it is not possible to send any TCP traffic to both container as tried with netcat and tcpdump. Netcat is able to send packets, but tcpdump on the primary and secondary does not show requests.
Anybody got a tip for me?
I just found the error.
As someone states in his blog, a specific port (4789) is blocked when virtualising with an ESXi stack. This is the default port for overlay network traffic.
Simply changing that port when initialising a swarm solves the problem.
docker swarm init --data-path-port 4788
I'm running a WSO2 container with all products together(apim-is-as-km-with-analytics) using mysql as database and I'm facing an error when the docker compose starts. My problem is on wso2-is server, it shows the following message:
[2021-02-26 21:38:17,531] [] INFO {org.wso2.carbon.mex2.internal.DynamicCRMCustomMexComponent} - DynamicCRMSupport MexServiceComponent bundle activated successfully.
[2021-02-26 21:38:19,923] [] INFO {org.apache.jasper.servlet.TldScanner} - At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[2021-02-26 21:38:20,098] [] INFO {org.wso2.carbon.identity.authenticator.x509Certificate.internal.X509CertificateServiceComponent} - X509 Certificate Servlet activated successfully..
[2021-02-26 21:38:23,807] [] ERROR {org.wso2.carbon.user.core.common.DefaultRealm} - nullType class java.lang.reflect.InvocationTargetException org.wso2.carbon.user.core.UserStoreException: nullType class java.lang.reflect.InvocationTargetException
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:397)
at org.wso2.carbon.user.core.common.DefaultRealm.initializeObjects(DefaultRealm.java:224)
at org.wso2.carbon.user.core.common.DefaultRealm.init(DefaultRealm.java:129)
at org.wso2.carbon.user.core.common.DefaultRealmService.initializeRealm(DefaultRealmService.java:276)
at org.wso2.carbon.user.core.common.DefaultRealmService.<init>(DefaultRealmService.java:102)
at org.wso2.carbon.user.core.common.DefaultRealmService.<init>(DefaultRealmService.java:115)
at org.wso2.carbon.user.core.internal.Activator.startDeploy(Activator.java:72)
at org.wso2.carbon.user.core.internal.BundleCheckActivator.start(BundleCheckActivator.java:61)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:842)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:834)
at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:791)
at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1013)
at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:365)
at org.eclipse.osgi.container.Module.doStart(Module.java:598)
at org.eclipse.osgi.container.Module.start(Module.java:462)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel$1.run(ModuleContainer.java:1820)
at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor$2$1.execute(EquinoxContainerAdaptor.java:150)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1813)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1770)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1735)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1661)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:234)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:345)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:351)
... 25 more
Caused by: org.wso2.carbon.user.core.UserStoreException: DB error occurred while persisting domain : PRIMARY & tenant id : -1234
at org.wso2.carbon.user.core.util.UserCoreUtil.persistDomain(UserCoreUtil.java:871)
at org.wso2.carbon.user.core.common.AbstractUserStoreManager.persistDomain(AbstractUserStoreManager.java:8595)
at org.wso2.carbon.user.core.ldap.ReadOnlyLDAPUserStoreManager.<init>(ReadOnlyLDAPUserStoreManager.java:243)
at org.wso2.carbon.user.core.ldap.UniqueIDReadOnlyLDAPUserStoreManager.<init>(UniqueIDReadOnlyLDAPUserStoreManager.java:148)
at org.wso2.carbon.user.core.ldap.UniqueIDReadWriteLDAPUserStoreManager.<init>(UniqueIDReadWriteLDAPUserStoreManager.java:122)
... 30 more
Caused by: java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
The last line on log shows a message
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
It's estrange because I already put the mysql driver on Dockerfile from wso2-is:
# copy MySQL JDBC connector to server home as a third party library
COPY --chown=wso2carbon:wso2 /binary/mysql-connector-java-8.0.17.jar ${WSO2_SERVER_HOME}/repository/components/dropins/
Does anybody know what am I missing?
I already check all jdbc address on toml files.
wso2am:3.2.0-alpine
wso2is:5.10.0-alpine
mysql:5.7.33
wso2am-analytics-dashboard:3.2.0-alpine
wso2am-analytics-worker:3.2.0-alpine
My problem was with mysql container. Even though the container's health was ok it was not ready yet:
mysql:5.7.33 "docker-entrypoint.s…" ... Up 5 minutes (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp
When I try to access using workbench it showed the message:
...Error Code: 2013 Lost connection to MySQL server at 'reading initial communication packet', system error: 0
Solution:
I added a script (wait-for-it) in all Dockerfiles(wso2am,wso2is,wso2am-analytics-worker) to check the availability of mysql before start wso2 server.
Dockerfile:
# install required packages. Need bash to wait-for-it
RUN apk add --no-cache netcat-openbsd \
bash
# Add wait-for-it
COPY --chown=wso2carbon:wso2 wait-for-it.sh ${USER_HOME}/
# initiate container after check if mysql is available and start WSO2 Carbon server
ENTRYPOINT ["/home/wso2carbon/wait-for-it.sh" , "cup-mysql:3306" , "--strict" , \
"--timeout=300" , "--" ,"/home/wso2carbon/docker-entrypoint.sh"]
And also increased the start_period of all containers to more than 60s since mysql spends 85s to start.
docker container logs wso2is:
wait-for-it.sh: waiting 300 seconds for cup-mysql:3306
wait-for-it.sh: cup-mysql:3306 is available after 85 seconds
JAVA_HOME environment variable is set to /opt/java/openjdk
CARBON_HOME environment variable is set to /home/wso2carbon/wso2is-5.10.0
docker-compose.yml:
mysql:
container_name: cup-mysql
image: mysql:5.7.33
ports:
- "3306:3306"
networks:
- wso2-network
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- ./conf/mysql/scripts:/docker-entrypoint-initdb.d
- ./conf/mysql/conf/my.cnf:/etc/mysql/my.cnf
ulimits:
nofile:
soft: 20000
hard: 40000
command: [--ssl=0]
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-uroot", "-proot"]
interval: 30s
timeout: 60s
retries: 5
start_period: 80s
is-as-km:
container_name: cup-is-as-km
build: ./dockerfiles/is-as-km/closeup
image: wso2is:5.10.0-alpine
healthcheck:
test: ["CMD", "nc", "-z","localhost", "9443"]
interval: 30s
start_period: 180s
retries: 20
depends_on:
mysql:
condition: service_healthy
volumes:
- ./conf/is-as-km:/home/wso2carbon/wso2-config-volume
ports:
- "9444:9443"
....
Windows Enterprise 2016 LTSB Version 1607. Installed Wiki.js with PostgreSQL. Has Node.js installed previously (v12.16.2).
Got to step 8 of wiki.js installation process using the Powershell:
node server
I receive this error:
PS C:\wiki> node server
Loading configuration from C:\wiki\config.yml... OK
2021-01-03T23:06:14.299Z [MASTER] info: =======================================
2021-01-03T23:06:14.300Z [MASTER] info: = Wiki.js 2.5.170 =====================
2021-01-03T23:06:14.301Z [MASTER] info: =======================================
2021-01-03T23:06:14.301Z [MASTER] info: Initializing...
2021-01-03T23:06:14.688Z [MASTER] info: Using database driver pg for postgres [ OK ]
2021-01-03T23:06:14.690Z [MASTER] info: Connecting to database...
2021-01-03T23:06:15.698Z [MASTER] error: Database Connection Error: ECONNREFUSED 127.0.0.1:5432
2021-01-03T23:06:15.698Z [MASTER] warn: Will retry in 3 seconds... [Attempt 1 of 10]
2021-01-03T23:06:18.700Z [MASTER] info: Connecting to database...
2021-01-03T23:06:19.703Z [MASTER] error: Database Connection Error: ECONNREFUSED 127.0.0.1:5432
2021-01-03T23:06:19.703Z [MASTER] warn: Will retry in 3 seconds... [Attempt 2 of 10]
... (you get the point)
2021-01-03T23:06:51.728Z [MASTER] error: Database Connection Error: ECONNREFUSED 127.0.0.1:5432
2021-01-03T23:06:51.729Z [MASTER] warn: Will retry in 3 seconds... [Attempt 10 of 10]
2021-01-03T23:06:54.730Z [MASTER] info: Connecting to database...
2021-01-03T23:06:55.733Z [MASTER] error: Database Initialization Error: connect ECONNREFUSED 127.0.0.1:5432
I realize that I forgot to create a PostgreSQL, so I used pgAdmin4.28 to create a "wiki" database. Error now changed to:
PS C:\wiki> node server
Loading configuration from C:\wiki\config.yml... OK
2021-01-04T00:27:21.979Z [MASTER] info: =======================================
2021-01-04T00:27:21.980Z [MASTER] info: = Wiki.js 2.5.170 =====================
2021-01-04T00:27:21.981Z [MASTER] info: =======================================
2021-01-04T00:27:21.982Z [MASTER] info: Initializing...
2021-01-04T00:27:22.363Z [MASTER] info: Using database driver pg for postgres [ OK ]
2021-01-04T00:27:22.365Z [MASTER] info: Connecting to database...
2021-01-04T00:27:22.428Z [MASTER] error: Database Connection Error: 28P01 undefined:undefined
2021-01-04T00:27:22.429Z [MASTER] warn: Will retry in 3 seconds... [Attempt 1 of 10]
2021-01-04T00:27:25.431Z [MASTER] info: Connecting to database...
2021-01-04T00:27:25.501Z [MASTER] error: Database Connection Error: 28P01 undefined:undefined
2021-01-04T00:27:25.501Z [MASTER] warn: Will retry in 3 seconds... [Attempt 2 of 10]
2021-01-04T00:27:28.503Z [MASTER] info: Connecting to database...
2021-01-04T00:27:28.545Z [MASTER] error: Database Connection Error: 28P01 undefined:undefined
2021-01-04T00:27:28.546Z [MASTER] warn: Will retry in 3 seconds... [Attempt 3 of 10]
Please send help! I appreciate all comments. Thanks!
I had similar issue with postgres and wiki.js.
Solution was to manually create the Database in postgres, BEFORE you run node server:
CREATE DATABASE wiki
Hope that saves you the time I had to spend to figure this out.
My environment is as follows: Windows 10 professional version number 20h2 node version v14.15.4 PostgreSQL V 13.1, the error content is as follows:
Loading configuration from D:\dev\workspace\wiki\config.yml... OK
2021-02-03T06:32:55.015Z [MASTER] info: =======================================
2021-02-03T06:32:55.016Z [MASTER] info: = Wiki.js 2.5.170 =====================
2021-02-03T06:32:55.016Z [MASTER] info: =======================================
2021-02-03T06:32:55.017Z [MASTER] info: Initializing...
2021-02-03T06:32:59.091Z [MASTER] info: Using database driver pg for postgres [ OK ]
2021-02-03T06:32:59.094Z [MASTER] info: Connecting to database...
2021-02-03T06:32:59.160Z [MASTER] error: Database Connection Error: 28P01
undefined:undefined
You just need to config.yml The database configuration in is modified as follows:
db:
type: postgres
# PostgreSQL / MySQL / MariaDB / MS SQL Server only:
host: localhost
port: 5432
user: postgres #YOU PostgreSQL USERNAME
pass: willasas#wiki. #YOU PostgreSQL PASSWORD
db: wiki #YOU DATABASE NAME
ssl: false
Then run the code
node server
And type in the address bar of your browser http://127.0.0.1 : 3000 / parallel return
After a couple hours of testing I realized some problems using postgres in wiki.js. These are some recommendations you can try in config.yml:
db:
type: postgres
# if you are using docker try using IP instead of localhost
host: localhost
port: 5432
# don't use _ here. It'll cause connection error undefined.
user: wikijs
# start with letter, if you start with # it will throw an error.
# I used a 18 long pass without any problem. Ex:
pass: wiki#projectW777!#
# you can use _ here. Ex:
db: prj_wiki
If you need to change the database password, this can help you:
ALTER USER postgres WITH PASSWORD 'xxx';
I had the same problem:
error: Database Connection Error: 28P01 undefined:undefined
I've solved it by modifying 86 line of file /var/lib/psql/data/pg_hba.conf, changing ident to md5 and then restarted database:
$ sudo systemctl restart postgresql
Additionally I've changed password in database:
$ sudo -u wikijs psql -d wiki
wiki=# \password wikijs
After that I've successfully executed node server.
Use this docker-compose file.
It solved my problems. Also make sure all the service names are unique, i.e. neither of the exist in your presently running docker containers
version: '3'
services:
db:
image: mysql:8.0
logging:
driver: "none"
restart: unless-stopped
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: mysql123!
MYSQL_DATABASE: wiki
wiki:
image: requarks/wiki:2
depends_on:
- db
environment:
DB_TYPE: mysql
DB_HOST: db
DB_PORT: 3307
DB_USER: root
DB_PASS: mysql123!
DB_NAME: wiki
restart: unless-stopped
ports:
- "9010:3000"
volumes:
db-data:
I have a jar which runs fine on my host; specifically, when I run
java -jar myjar.jar
I get the expected output:
[2018-12-05 16:46:53.917] boot - 21252 INFO [main] --- Application: No active profile set, falling back to default profiles: default
[2018-12-05 16:47:00.855] boot - 21252 INFO [main] --- Application: Started Application in 8.176 seconds (JVM running for 9.106)
This is the Core Data Micro Service.
[2018-12-05 16:47:00.856] boot - 21252 INFO [main] --- Application: Registering to queue for events
[2018-12-05 16:47:00.857] boot - 21252 INFO [main] --- ZeroMQEventSubscriber: Getting subscriber, listening to tcp://localhost:5565
[2018-12-05 16:47:00.915] boot - 21252 INFO [main] --- ZeroMQEventSubscriber: Watching for new Event messages...
But then, I try to run the same jar inside a docker container. So I create the image like this:
FROM openjdk:8-jdk-alpine
COPY myjar.jar /opt/spring-cloud/lib/
ENTRYPOINT ["/usr/bin/java"]
CMD ["-jar", "/opt/spring-cloud/lib/myjar.jar"]
EXPOSE 48080
and run it:
sudo docker run [ID]
but this time, I get this exception from the container logs (this is only a part of the exception because it is too big, but I can show it all if needed):
[2018-12-07 08:30:31.447] boot - 1 INFO [main] --- Application: No active profile set, falling back to default profiles: default
[2018-12-07 08:32:35.423] boot - 1 ERROR [main] --- SpringApplication: Application startup failed
...
...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'readingControllerImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.edgexfoundry.dao.ValueDescriptorRepository org.edgexfoundry.controller.impl.ReadingControllerImpl.valDescRepos; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'valueDescriptorRepository': Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 120000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 120000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
...
...
Caused by: com.mongodb.MongoTimeoutException: Timed out after 120000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
at com.mongodb.BaseCluster.getServer(BaseCluster.java:82)
at com.mongodb.DBTCPConnector.getServer(DBTCPConnector.java:664)
at com.mongodb.DBTCPConnector.access$500(DBTCPConnector.java:40)
at com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:513)
at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:456)
at com.mongodb.DBTCPConnector.getPrimaryPort(DBTCPConnector.java:415)
at com.mongodb.DBCollectionImpl.createIndex(DBCollectionImpl.java:378)
at com.mongodb.DBCollection.createIndex(DBCollection.java:597)
at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.createIndex(MongoPersistentEntityIndexCreator.java:142)
... 57 more
Mongo has been started in another container through docker-compose (together with other services in other containers):
ps aux | grep mongo
root 16226 0.0 0.0 4340 768 ? Ss 10:27 0:00 /bin/sh -c /edgex/mongo/config/launch-edgex-mongo.sh
root 16292 0.0 0.0 4340 764 ? S 10:27 0:00 /bin/sh /edgex/mongo/config/launch-edgex-mongo.sh
root 16293 0.5 0.3 961168 61400 ? SLl 10:27 0:05 mongod --smallfiles
This is the docker-compose file:
version: '3'
services:
volume:
image: edgexfoundry/docker-edgex-volume:0.6.0
container_name: edgex-files
networks:
- edgex-network
volumes:
- db-data:/data/db
- log-data:/edgex/logs
- consul-config:/consul/config
- consul-data:/consul/data
mongo:
image: edgexfoundry/docker-edgex-mongo:0.6.0
ports:
- "27017:27017"
container_name: edgex-mongo
hostname: edgex-mongo
networks:
- edgex-network
volumes:
- db-data:/data/db
- log-data:/edgex/logs
- consul-config:/consul/config
- consul-data:/consul/data
depends_on:
- volume
.... more services...
networks:
edgex-network:
driver: "bridge
And the mongo db configuration properties:
spring.data.mongodb.username=core
spring.data.mongodb.password=password
spring.data.mongodb.database=coredata
#change to localhost when running locally during development
# (or set hosts to point edgex-mongo to the mongo host
spring.data.mongodb.host=localhost
#spring.data.mongodb.host=edgex-mongo
spring.data.mongodb.port=27017
spring.data.mongodb.connectTimeout=120000
spring.data.mongodb.socketTimeout=60000
spring.data.mongodb.maxWaitTime=120000
spring.data.mongodb.socketKeepAlive=true
Any ideas what may be going wrong?
There are two things going wrong here, first of all spring tries to connect to your mongodb on localhost, within docker this does not work since localhost references to the current container where of course no mongodb is available. To fix this you have to comment out this line and uncomment the next line which lists the host as edgex-mongo which corresponds with the hostname of your mongodb container, so spring knows to connect to that container.
However when you would do this you would run into the issue that it would not recognize edgex-mongo since it has no connection to this container. edgex-mongo is inside a bridged network which requires you to add the spring container to this network by using the following command:
docker run --network edgex--network [image]
I hope this helps you