Alright so i have spring-boot java application, mysql db and nginx.
I start them and it looks like this (command i use is docker-compose up that is all i need to execute):
The Error that i have in my application workaround_app_1 is following:
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.4.RELEASE)
14:46:59.083 INFO [c.b.w.WorkaroundApplication] Starting WorkaroundApplication on 9b42d0d4614b with PID 48 (/app/target/classes started by root in /app)
14:46:59.089 INFO [c.b.w.WorkaroundApplication] The following profiles are active: devdock
14:47:11.985 INFO [o.a.c.h.Http11NioProtocol] Initializing ProtocolHandler ["https-jsse-nio-8080"]
14:47:12.015 INFO [o.a.c.c.StandardService] Starting service [Tomcat]
14:47:12.016 INFO [o.a.c.c.StandardEngine] Starting Servlet engine: [Apache Tomcat/9.0.17]
14:47:13.993 INFO [o.a.c.c.C.[.[.[/workaround]] Initializing Spring embedded WebApplicationContext
14:47:13.996 INFO [o.s.w.c.ContextLoader] Root WebApplicationContext: initialization completed in 14635 ms
14:47:17.906 INFO [c.z.h.HikariDataSource] HikariPool-1 - Starting...
14:47:19.294 ERROR [c.z.h.p.HikariPool] HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356)
at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:73)
at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:142)
at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:113)
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$aadd42f9.CGLIB$jpaVendorAdapter$4(<generated>)
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$aadd42f9$$FastClassBySpringCGLIB$$962bc1e0.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(Configuratio
That goes on and one till at the end you see
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
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 com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91)
at com.mysql.cj.NativeSession.connect(NativeSession.java:152)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
... 188 common frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
... 191 common frames omitted
This is my docker-compose:
version: '3'
services:
nginx:
container_name: some-nginx
image: nginx:1.13
restart: always
ports:
- 8080:8080
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
depends_on:
- app
mysql:
container_name: workaround-mysql
image: mysql/mysql-server:5.7
environment:
MYSQL_DATABASE: workaround
MYSQL_USER: springuser
MYSQL_PASSWORD: admin
MYSQL_ROOT_PASSWORD: admin
MYSQL_ROOT_HOST: '%'
ports:
- "3308:3306"
restart: always
app:
restart: always
build: ./
working_dir: /app
volumes:
- ./:/app
- ~/.m2:/root/.m2
expose:
- "8080"
command: mvn clean spring-boot:run
depends_on:
- mysql
And here is my application.properties:
###################################
#---------DATABASE
###################################
#
# URL for the mysql db
spring.datasource.url=jdbc:mysql://workaround-mysql:3308/workaround?serverTimezone=UTC&max_allowed_packet=15728640
# User name in mysql
spring.datasource.username=springuser
# Password for mysql
spring.datasource.password=admin
My Dockerfile only contains one liner: FROM openjdk:12-jdk
All of that in mind, What is happening why i cannot connect to my database? When i do it out of docker, all works fine on localhost. Bud cant get it working with this setup. Could that be that somehow my workaround_app_1 started sooner then mysql and now cant function? Bud in my docker-compose I specified that it depends on mysql to be started right ?Im new to docker + nginx.
Notes:
I have tried different ports for mysql bud that doesnt seem to be issue. I also dont think its issue with resources or anything related so hardware constraints. Are my configurations proper ? Btw i use Docker for windows, 64bit machine jdk12. I have tried some demo applications and they were working fine.
The ports mapping in your docker-compose.yml is only relevant for the host, so you'll be able to connect to your DB through localhost:3308. But inside your other docker-compose containers (that is, the compose default network), you'd have to use workaround-mysql:3306.
Ok so the issue was , mysql got stuck on :
[Entrypoint] Starting MySQL 5.7.26-1.1.11
Nothing could connect to it.
Application that needed it was starting up and it could not connect so it was throwing errors.
Here is another question of mayne regarding this issue and you can see its solved :
Docker MySQL - can't connect from Spring Boot app to MySQL database
You can connect from host to db in docker container, but you cannot connect to db in docker container from other docker container.
Check mysql settings and allow connections from app container's IP (or docker network).
Related
I developed a spring boot application to store login information via redis. I have following docker-compose.yml:
version: "3.9"
services:
web:
build: .
ports:
- "8082:8082"
links:
- redis
redis:
image: redis
container_name: redis
hostname: redis-db
ports:
- "6379:6379"
command: redis-server --port 6379 --bind 0.0.0.0 --protected-mode no
Dockerfile:
FROM openjdk:8-jre-alpine
VOLUME /tmp
COPY app.jar app.jar
EXPOSE 8082
ENTRYPOINT ["java", "-jar", "app.jar"]
In the Spring Boot Application, I just use following application.properties to setup the Redis Connection:
server.port = 8082
spring.redis.host=redis-db
spring.redis.port=6379
I access the repository via CrudRepository and QueryByExampleExecutor. Every time I try to access the data, I get the following error:
sgartner-web-1 | 2021-11-25 01:22:53.600 ERROR 1 --- [nio-8082-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379] with root cause
sgartner-web-1 |
sgartner-web-1 | java.net.ConnectException: Connection refused
sgartner-web-1 | at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_212]
sgartner-web-1 | at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_212]
sgartner-web-1 | at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330) ~[netty-transport-4.1.69.Final.jar!/:4.1.69.Final]
sgartner-web-1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334) ~[netty-transport-4.1.69.Final.jar!/:4.1.69.Final]
sgartner-web-1 | at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707) ~[netty-transport-4.1.69.Final.jar!/:4.1.69.Final]
sgartner-web-1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) ~[netty-transport-4.1.69.Final.jar!/:4.1.69.Final]
sgartner-web-1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) ~[netty-transport-4.1.69.Final.jar!/:4.1.69.Final]
sgartner-web-1 | at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.69.Final.jar!/:4.1.69.Final]
sgartner-web-1 | at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986) ~[netty-common-4.1.69.Final.jar!/:4.1.69.Final]
sgartner-web-1 | at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.69.Final.jar!/:4.1.69.Final]
sgartner-web-1 | at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.69.Final.jar!/:4.1.69.Final]
sgartner-web-1 | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
I already have tested the application "normal" instances of redis and the application. What seems odd to me is the "Unable to connect to localhost:6379]", even though I'm not trying to connect to localhost.
Testing this behavior while running the application outside of a container shows, that it recognises the changed hostname and doesn't try to connect to localhost...
The specified redis command also doesn't seem to be the problem: tested this with running redis outside of a container with the same command and trying to connect to it via a VM.
I would really appreciate a solution or another possible cause to look into. Thanks to whoever replies to this!
as per logs it clearly says that web application is not able to connect to redis port 6379. Can you try expose 6379 in Dockerfile? , please check first are you able to pint 6379 from your local machine. Seems network issue.
See is this helps.
Docker can't connect to redis from another service
I am trying to deploy my application in docker (on Windows 10), in compose with a Postgres container. When I execute docker-compose up, I see the following log:
Starting postgres ... done
Recreating application ... done
Attaching to postgres, application
postgres |
postgres | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres |
postgres | 2021-08-20 14:51:49.721 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres | 2021-08-20 14:51:49.721 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres | 2021-08-20 14:51:49.741 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2021-08-20 14:51:49.858 UTC [21] LOG: database system was interrupted; last known up at 2021-08-20 14:50:34 UTC
postgres | 2021-08-20 14:51:51.363 UTC [21] LOG: database system was not properly shut down; automatic recovery in progress
postgres | 2021-08-20 14:51:51.377 UTC [21] LOG: redo starts at 0/1661A88
postgres | 2021-08-20 14:51:51.377 UTC [21] LOG: invalid record length at 0/1661AC0: wanted 24, got 0
postgres | 2021-08-20 14:51:51.377 UTC [21] LOG: redo done at 0/1661A88
postgres | 2021-08-20 14:51:51.471 UTC [1] LOG: database system is ready to accept connections
Then the container of my application tries to start and after the banner "Spring Boot" etc. I get an error:
application | 2021-08-20 14:52:23.440 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
application |
application | org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
application | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:303) ~[postgresql-42.2.20.jar!/:42.2.20]
Here is my docker-compose.yml
version: "3"
services:
db:
image: postgres:11.13-alpine
container_name: postgres
ports:
- 5432:5432
volumes:
- ./pgdata:/var/lib/postgresql/data
environment:
- POSTGRES_DB=my_db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=root
- PGDATA=/var/lib/postgresql/data/mnt
restart: always
app:
build: .
container_name: application
ports:
- 8085:8085
environment:
- POSTGRES_HOST=db
restart: always
links:
- db
my Dockerfile:
FROM openjdk:11
ADD target/my-app.jar my-app.jar
EXPOSE 8085
ENTRYPOINT ["java" , "-jar", "my-app.jar"]
application.properties:
spring.datasource.url=jdbc:postgresql://${POSTGRES_HOST}:5432/my_db
spring.datasource.username=postgres
spring.datasource.password=root
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=none
spring.liquibase.change-log=classpath:liquibase/changelog.xml
logging.level.org.springframework.jdbc.core = TRACE
What is the problem? Why my application looking for Postgres on localhost and doesn't apply enviroment variable? Inside docker container the host for postgres should be different, isn't it? I have even tried to hardcode postgres host in application.properties to jdbc:postgresql://db:5432/my_db , but it continue to use localhost. How can I fix it?
try to use in this way
environment:
POSTGRES_HOST: db
I'm trying to deploy a Quarkus app to a Kubernetes cluster, but I got the following stacktrace:
exec java -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -XX:+ExitOnOutOfMemoryError -cp . -jar /deployments/quarkus-run.jar
__ ____ __ _____ ___ __ ____ ______
--/ __ \/ / / / _ | / _ \/ //_/ / / / __/
-/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2021-05-11 16:47:19,455 ERROR [io.qua.run.Application] (main) Failed to start application (with profile prod): java.lang.NumberFormatException: SRCFG00029: Expected an integer value, got "tcp://10.233.12.82:80"
at io.smallrye.config.Converters.lambda$static$60db1e39$1(Converters.java:104)
at io.smallrye.config.Converters$EmptyValueConverter.convert(Converters.java:949)
at io.smallrye.config.Converters$TrimmingConverter.convert(Converters.java:970)
at io.smallrye.config.Converters$BuiltInConverter.convert(Converters.java:872)
at io.smallrye.config.Converters$OptionalConverter.convert(Converters.java:790)
at io.smallrye.config.Converters$OptionalConverter.convert(Converters.java:771)
at io.smallrye.config.SmallRyeConfig.getValue(SmallRyeConfig.java:225)
at io.smallrye.config.SmallRyeConfig.getOptionalValue(SmallRyeConfig.java:270)
at io.quarkus.arc.runtime.ConfigRecorder.validateConfigProperties(ConfigRecorder.java:37)
at io.quarkus.deployment.steps.ConfigBuildStep$validateConfigProperties1249763973.deploy_0(ConfigBuildStep$validateConfigProperties1249763973.zig:328)
at io.quarkus.deployment.steps.ConfigBuildStep$validateConfigProperties1249763973.deploy(ConfigBuildStep$validateConfigProperties1249763973.zig:40)
at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:576)
at io.quarkus.runtime.Application.start(Application.java:90)
at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:100)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:48)
at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:25)
I build the Docker image with the default dockerfile, and my quarkus-related dependencies are the following:
dependencies {
implementation(enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}"))
implementation("org.optaplanner:optaplanner-quarkus")
implementation("io.quarkus:quarkus-resteasy")
implementation("io.quarkus:quarkus-vertx")
implementation("io.quarkus:quarkus-resteasy-jackson")
implementation("io.quarkus:quarkus-undertow-websockets")
implementation("io.quarkus:quarkus-smallrye-health")
}
I'm using Quarkus 1.13.3.Final, and I've written a helm chart for my deployment by hand. The deployed dockerfile runs fine on my machine, and the kubernetes deployment descriptor does not have that IP address in it. I think that IP is a ClusterIP of the cluster.
Any idea? Thanks
It's due to the docker link variables that kubernetes mimics for Service names in scope; it bites people a lot when they have generically named services such as { apiVersion: v1, kind: Service, metadata: { name: http }, ... as it will cheerfully produce environment variables of the form HTTP_PORT=tcp://10.233.12.82:80 in the Pod, and things such as Spring boot or evidently Quarkus which coerce env-vars into configuration overrides can cause the exact outcome you're experiencing
The solution is (a) don't name Services with bland names (b) "mask off" the offensive env-vars for the Pod:
...
containers:
- ...
env:
- name: HTTP_PORT
# it doesn't need a value:, it just needs the name to be specified
# so it hides the injected version
- ... any remaining env-vars you really want
I have a really confusing problem when I use Quarkus and Keycloak in docker compose. When I set the environment variables to override the dev configuration aka quarkus.oidc.auth-server-url and the quarkus.datasource.jdbc.url and then try to run the docker-compose file an error message appears. It says that my auth-server-url is not correct, but I do not see an typo or a mistake in my auth-server-url.
Error message:
dbk-core | exec java -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -XX:+ExitOnOutOfMemoryError -cp . -jar /deployments/app.jar
dbk-core | __ ____ __ _____ ___ __ ____ ______
dbk-core | --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
dbk-core | -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
dbk-core | --\___\_\____/_/ |_/_/|_/_/|_|\____/___/
dbk-core | 11:32:08 ERROR [io.qu.application] (main) Failed to start application (with profile prod): io.quarkus.oidc.OIDCException: OIDC server is not available at the 'quarkus.oidc.auth-server-url' URL. Please make sure it is correct. Note it has to end with a realm value if you work with Keycloak, for example: 'https://localhost:8180/auth/realms/quarkus'
..........
dbk-core | at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
dbk-core | at java.base/java.lang.Thread.run(Thread.java:834)
dbk-core | Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: keycloak/172.24.0.3:8180
dbk-core | Caused by: java.net.ConnectException: Connection refused
dbk-core | at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
My docker-compose.yml
services:
database:
build:
context: ./db-init
dockerfile: Dockerfile.db
container_name: dbk-database
ports:
- 5432:5432
volumes:
- "$HOME/databases/postgres:/var/lib/postgresql/data"
keycloak:
image: quay.io/keycloak/keycloak:latest
container_name: dbk-keycloak
environment:
DB_VENDOR: POSTGRES
DB_ADDR: database
DB_DATABASE: keycloak_database
DB_USER: keycloak
DB_SCHEMA: public
DB_PASSWORD: keycloak
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: admin
ports:
- 8180:8080
depends_on:
- database
core:
image: registry.gitlab.com/baudoku/dbk-core:dev
container_name: dbk-core
environment:
QUARKUS_OIDC_AUTH_SERVER_URL: http://keycloak:8180/auth/realms/dbk
QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://database:5432/dbk_core_database
depends_on:
- database
- keycloak
ports:
- 8080:8080
My Quarkus application.properties:
quarkus.oidc.auth-server-url=http://localhost:8180/auth/realms/dbk
quarkus.oidc.client-id=dbk-core
quarkus.oidc.credentials.secret=3a17e7e8-0099-49d9-8e33-d0eb954daba0
quarkus.datasource.db-kind = postgresql
quarkus.datasource.username = core
quarkus.datasource.password = core
quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:5432/dbk_core_database
When i start the keycloak service with docker and my quarkus application manually with ./mvnw quarkus:dev all is working.
I solved the problem myself :). The problem was my quarkus.oidc.auth-server-url because I used the wrong port. The solution was to use the inner port of the keycloak service and not the expose port.
The correct auth-server-url is: http://keycloak:8080/auth/realms/dbk
Correct docker-compose:
core:
image: registry.gitlab.com/baudoku/dbk-core:dev
container_name: dbk-core
environment:
QUARKUS_HTTP_PORT: 7000
QUARKUS_OIDC_AUTH_SERVER_URL: http://keycloak:8080/auth/realms/dbk
QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://database:5432/dbk_core_database
depends_on:
- database
- keycloak
ports:
- 8080:7000
I have 2 docker images 1) for couchdb and 2) a web application. The web application couldnt able to talk to the couchdb which is running on the same machine.
When I access couchdb directly it is working http://127.0.0.1:5984/_utils/#database/
http://0.0.0.0:5984/_utils/#database/
What am I missing any pointers?
| Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:5984 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
hashgraph_1 | at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
hashgraph_1 | at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
hashgraph_1 | at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
hashgraph_1 | at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
hashgraph_1 | at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
hashgraph_1 | at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
hashgraph_1 | at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
hashgraph_1 | at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
hashgraph_1 | at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
hashgraph_1 | at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
my docker compose file
version: "3"
services:
hashgraph:
build: "./"
depends_on:
- couchdb
deploy:
replicas: 1
restart_policy:
condition: always
ports:
- "51200-51299:51200-51299"
couchdb:
image: couchdb:2.1
ports:
- "5984:5984"
deploy:
replicas: 1
restart_policy:
condition: always
Output of docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cc7e37cd6260 hashgraphexperiments_hashgraph "java -jar swirlds.j…" About a minute ago Up About a minute 50200-50299/tcp, 0.0.0.0:51200-51299->51200-51299/tcp hashgraphexperiments_hashgraph_1
9f4767b36aea couchdb:2.1 "tini -- /docker-ent…" 2 hours ago Up About a minute 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp hashgraphexperiments_couchdb_1
depends_on: it just wait to the other container to be started.
Whenever you want to call the couchdb from the hashgraph container code, you need to use couchdb:5984 instead of localhost:5984
Networking in Compose
You can also explicitly use the links entry instead of depends_on.
The description of links is
links: Link to containers in another service. Either specify both the service name and a link alias (SERVICE:ALIAS), or just the service name.
Links also express dependency between services in the same way as depends_on, so they determine the order of service startup.
version: "3"
services:
hashgraph:
build: .
links:
- couchdb:couchdb
deploy:
replicas: 1
restart_policy:
condition: always
ports:
- "51200-51299:51200-51299"
couchdb:
image: couchdb:2.1
ports:
- 5984:5984
deploy:
replicas: 1
restart_policy:
condition: always