Communication between JHipster Registry and Keyloak from different containers - spring-boot

I am trying to implement a simple microservice infrastructure Jhipster. When I create microservice and and gateway I selected Oauth2 as security. The projects are created. I started Keyclok using following keycloak.yml. It seems it is started successfully. Realms, clients and users are created
docker-compose -f src/main/docker/keycloak.yml up
This configuration is intended for development purpose, it's **your** responsibility to harden it for production
version: '3.8'
services:
keycloak:
image: jboss/keycloak:16.1.0
command:
[
'-b',
'0.0.0.0',
'-Dkeycloak.migration.action=import',
'-Dkeycloak.migration.provider=dir',
'-Dkeycloak.migration.dir=/opt/jboss/keycloak/realm-config',
'-Dkeycloak.migration.strategy=OVERWRITE_EXISTING',
'-Djboss.socket.binding.port-offset=1000',
'-Dkeycloak.profile.feature.upload_scripts=enabled',
]
volumes:
- ./realm-config:/opt/jboss/keycloak/realm-config
environment:
- KEYCLOAK_USER=admin
- KEYCLOAK_PASSWORD=admin
- DB_VENDOR=h2
# If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 127.0.0.1:9080:9080
- 127.0.0.1:9443:9443
- 127.0.0.1:10990:10990
Then I tried to run jhipster registry with following command.
docker-compose -f src/main/docker/jhipster-registry.yml up
jhipster-registry.yml
# This configuration is intended for development purpose, it's **your** responsibility to harden it for production
version: '3.8'
services:
jhipster-registry:
image: jhipster/jhipster-registry:v7.3.0
volumes:
- ./central-server-config:/central-config
# When run with the "dev" Spring profile, the JHipster Registry will
# read the config from the local filesystem (central-server-config directory)
# When run with the "prod" Spring profile, it will read the configuration from a Git repository
# See https://www.jhipster.tech/jhipster-registry/#spring-cloud-config
environment:
- _JAVA_OPTIONS=-Xmx512m -Xms256m
- SPRING_PROFILES_ACTIVE=dev,api-docs,oauth2
- SPRING_SECURITY_USER_PASSWORD=admin
- JHIPSTER_REGISTRY_PASSWORD=admin
- SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=native
- SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_LOCATIONS=file:./central-config/localhost-config/
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=git
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_URI=https://github.com/jhipster/jhipster-registry/
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_PATHS=central-config
# For keycloak to work, you need to add '127.0.0.1 keycloak' to your hosts file
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/auth/realms/jhipster
- SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=jhipster-registry
- SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=jhipster-registry
# If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 127.0.0.1:8761:8761
I added following lines to etc/hosts
127.0.0.1 keycloak
127.0.0.1 jhipster-registry
When I check jhipster registry log, there are some exceptions regarding to euroka.
INFO 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_JHIPSTER-REGISTRY/jhipsterReg
istry:8e0fa8188498e671983ba4002054c82d: registering service...
0416b4df1858_docker_jhipster-registry_1 | 2022-04-14 20:06:33.350 INFO 1 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndp
oint{ serviceUrl='http://admin:admin#localhost:8761/eureka/}, exception=java.net.ConnectException: Connection refused (Connection refused) stacktrace=com.sun.jersey.api.client.ClientHa
ndlerException: java.net.ConnectException: Connection refused (Connection refused)
0416b4df1858_docker_jhipster-registry_1 | at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)
0416b4df1858_docker_jhipster-registry_1 | at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)
0416b4df1858_docker_jhipster-registry_1 | at com.sun.jersey.api.client.Client.handle(Client.java:652)
0416b4df1858_docker_jhipster-registry_1 | at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
0416b4df1858_docker_jhipster-registry_1 | at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
0416b4df1858_docker_jhipster-registry_1 | at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.register(AbstractJerseyEurekaHttpClient.java:57)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient.execute(MetricsCollectingEurekaHttpClient.java:73)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:121)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:80)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:120)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:876)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:121)
0416b4df1858_docker_jhipster-registry_1 | at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:101)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.lang.Thread.run(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | Caused by: java.net.ConnectException: Connection refused (Connection refused)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | at java.base/java.net.Socket.connect(Unknown Source)
0416b4df1858_docker_jhipster-registry_1 | at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)
0416b4df1858_docker_jhipster-registry_1 | at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
0416b4df1858_docker_jhipster-registry_1 | at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144)
0416b4df1858_docker_jhipster-registry_1 | at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134)
0416b4df1858_docker_jhipster-registry_1 | at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:605)
0416b4df1858_docker_jhipster-registry_1 | at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:440)
0416b4df1858_docker_jhipster-registry_1 | at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
0416b4df1858_docker_jhipster-registry_1 | at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118)
0416b4df1858_docker_jhipster-registry_1 | at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
0416b4df1858_docker_jhipster-registry_1 | at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173)
0416b4df1858_docker_jhipster-registry_1 | ... 29 more
0416b4df1858_docker_jhipster-registry_1 |
If I try to access jhipster registry console with 127.0.0.1:8761 I get exception regarding to authorization
0416b4df1858_docker_jhipster-registry_1 | 2022-04-14 20:10:08.796 WARN 1 --- [ XNIO-1 task-2] o.z.problem.spring.common.AdviceTraits : Unauthorized: Full authentication is required
to access this resource
Can you help to realize problem. I think there are 2 problems. One of them is related to connecting Euroka. But I did not get reason. Jhipster Registry already contains Euroka. Other problem is related to communication between keycloak and jhipster registry
Edited compose file
# This configuration is intended for development purpose, it's **your** responsibility to harden it for production
version: '3.8'
services:
jhipster-registry:
image: jhipster/jhipster-registry:v7.3.0
volumes:
- ./central-server-config:/central-config
# When run with the "dev" Spring profile, the JHipster Registry will
# read the config from the local filesystem (central-server-config directory)
# When run with the "prod" Spring profile, it will read the configuration from a Git repository
# See https://www.jhipster.tech/jhipster-registry/#spring-cloud-config
environment:
- _JAVA_OPTIONS=-Xmx512m -Xms256m
- SPRING_PROFILES_ACTIVE=dev,api-docs,oauth2
- SPRING_SECURITY_USER_PASSWORD=admin
- JHIPSTER_REGISTRY_PASSWORD=admin
- SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=native
- SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_LOCATIONS=file:./central-config/localhost-config/
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=git
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_URI=https://github.com/jhipster/jhipster-registry/
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_PATHS=central-config
# For keycloak to work, you need to add '127.0.0.1 keycloak' to your hosts file
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/auth/realms/jhipster
- SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=jhipster-registry
- SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=jhipster-registry
# If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 127.0.0.1:8761:8761
keycloak:
image: jboss/keycloak:16.1.0
command:
[
'-b',
'0.0.0.0',
'-Dkeycloak.migration.action=import',
'-Dkeycloak.migration.provider=dir',
'-Dkeycloak.migration.dir=/opt/jboss/keycloak/realm-config',
'-Dkeycloak.migration.strategy=OVERWRITE_EXISTING',
'-Djboss.socket.binding.port-offset=1000',
'-Dkeycloak.profile.feature.upload_scripts=enabled',
]
volumes:
- ./realm-config:/opt/jboss/keycloak/realm-config
environment:
- KEYCLOAK_USER=admin
- KEYCLOAK_PASSWORD=admin
- DB_VENDOR=h2
# If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 127.0.0.1:9080:9080
- 127.0.0.1:9443:9443
- 127.0.0.1:10990:10990

127.0.0.1 is localhost, but each container is running in own network namespace, so each container has own 127.0.0.1/localhost + your OS has also own 127.0.0.1/localhost.
Your setup will be "sharing" one OS's 127.0.0.1/localhost with containers if you use host network for your container = set the network_mode key to host: https://docs.docker.com/compose/compose-file/compose-file-v3/#network_mode

If you combine both docker compose files, JHipster will be able to communicate with Keycloak on host keyckoak. This has an additional benefit. You will only need to run a single command to start both services. You will also be able to stop them with a single command.
You will still need to keep your /etc/hosts entry for keycloak so that you can access keycloak login page in your browser.
To run start keycloak first and then start jhipster.
Docker-compose up keycloak
Wait for full start
Docker-compose up jhipster

Related

Cannot connect a spring boot app to a kafka cluster running on a multipass virtual machine

I set up a kafka cluster on a multipass virtual machine:
Start the ZooKeeper service
$ bin/zookeeper-server-start.sh config/zookeeper.properties
Start the Kafka broker service
$ bin/kafka-server-start.sh config/server.properties
When I try to connect to it with my spring boot application, I get a java.net.UnkownHostException
2023-01-29T19:41:43.877-08:00 WARN 46599 --- [ | my-client-id] org.apache.kafka.clients.NetworkClient : [AdminClient clientId=my-client-id] Error connecting to node zebra:9092 (id: 0 rack: null)
java.net.UnknownHostException: zebra
at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:801) ~[na:na]
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1519) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1377) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1305) ~[na:na]
at org.apache.kafka.clients.DefaultHostResolver.resolve(DefaultHostResolver.java:27) ~[kafka-clients-3.3.1.jar:na]
at org.apache.kafka.clients.ClientUtils.resolve(ClientUtils.java:110) ~[kafka-clients-3.3.1.jar:na]
at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.currentAddress(ClusterConnectionStates.java:510) ~[kafka-clients-3.3.1.jar:na]
at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.access$200(ClusterConnectionStates.java:467) ~[kafka-clients-3.3.1.jar:na]
at org.apache.kafka.clients.ClusterConnectionStates.currentAddress(ClusterConnectionStates.java:173) ~[kafka-clients-3.3.1.jar:na]
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:990) ~[kafka-clients-3.3.1.jar:na]
at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:301) ~[kafka-clients-3.3.1.jar:na]
at org.apache.kafka.clients.admin.KafkaAdminClient$AdminClientRunnable.sendEligibleCalls(KafkaAdminClient.java:1143) ~[kafka-clients-3.3.1.jar:na]
at org.apache.kafka.clients.admin.KafkaAdminClient$AdminClientRunnable.processRequests(KafkaAdminClient.java:1403) ~[kafka-clients-3.3.1.jar:na]
at org.apache.kafka.clients.admin.KafkaAdminClient$AdminClientRunnable.run(KafkaAdminClient.java:1346) ~[kafka-clients-3.3.1.jar:na]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
multipass 'zebra' vm ipv4
'multipass info zebra' output
I tried using telnet and the connection worked, but the springboot app still cannot connect.

The Spring boot app doesn't seem to run after putting it in container

I am trying to create docker containers and I was trying to 1 for MySql and another for Spring io. The DB container is running OK but the spring boot container comes at a point and exits. I have searched and tried many thing but I can't seem to be able to solve it, the thing that I concluded that it seems that something is wrong with the database environment or aplication.properties or maybe it could be somewhere else. I would be so grateful if someone could guide me to the solution.
application.properties:
spring.datasource.url=jdbc:mysql://DB_containerfile:3306/phase2?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
spring.datasource.username=testuser
spring.datasource.password= testuser#123
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver
dockerfile:
FROM openjdk:17
ADD target/springboot-crud-api-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
docker-compose.yml:
version: '3.8'
services:
DB_containerfile:
image: mysql:latest
container_name: DB_containerfile
environment:
- MYSQL_ROOT_PASSWORD=////////////
- MYSQL_DATABASE=phase2
- MYSQL_USER=testuser
- MYSQL_PASSWORD=testuser#123
backend_containerfile:
image: backend_image
container_name: backend_containerfile
ports:
- 8080:8080
build:
context: ./
dockerfile: Dockerfile
depends_on:
- DB_containerfile
NOTE: I assigned the password that I enter when I write this command on the cmd "mysql -u root -p" to MYSQL_ROOT_PASSWORD
Spring boot log:
backend_containerfile | 2022-12-02 06:02:54.757 WARN 1 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
backend_containerfile | 2022-12-02 06:02:56.040 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
backend_containerfile |
backend_containerfile | java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
backend_containerfile | at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]
backend_containerfile | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]
backend_containerfile | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]
backend_containerfile | at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]
backend_containerfile | at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]
backend_containerfile | at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]backend_containerfile | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.6.12.Final.jar!/:5.6.12.Final]
What I tried:
1)I tried docker volume prune.
2)I tried removing the
- MYSQL_USER=testuser
- MYSQL_PASSWORD=testuser#123
spring.datasource.username=testuser
spring.datasource.password= testuser#123\`
and only going with
- MYSQL_ROOT_PASSWORD=////////////
3)I tried both
spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name= com.mysql.jdbc.Driver
4)I put allowPublicKeyRetrieval=true in spring.datasource.url
And many other thing I tried but the result remained the same.
Sorry, for the long question but I really tried to figure out the problem by myself but now I need someone's insight. And thank you.
try to use this driverClassName in application.properties
spring.datasource.driverClassName=com.mysql.jdbc.Driver
Have you tried to start only Mysql db in the container and connect to it from you IDE?
Thankfully I found the problem it was because I haven't connected the database and spring io. I will post the solution for my case, in case it helps someone.
spring.datasource.url=jdbc:mysql://DB_containerfile:3306/phase2?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
spring.datasource.username=testuser
spring.datasource.password= testuser#123
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name= com.mysql.jdbc.Driver
FROM openjdk:17
ADD target/*.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
then run the following commands in the project terminal:
docker-compose down
mvn clean
mvn clean install -DskipTests=true
docker network ls
docker network create spring-net //if not created
docker-compose up //then CTRL+C
docker network connect spring-net DB_containerfile
docker container inspect DB_containerfile
docker ps -a
docker-compose up

Docker compose error on mysql db connect for spring boot app Caused by: java.net.UnknownHostException: [duplicate]

This question already has answers here:
Communications link failure , Spring Boot + MySql +Docker + Hibernate
(6 answers)
Closed 3 years ago.
I have spring boot app
My Dockerfile is
FROM openjdk:8-jdk-alpine
EXPOSE 8080
ARG JAR_FILE=target/demo-0.0.1-SNAPSHOT.jar
ADD ${JAR_FILE} demo.jar
ENTRYPOINT ["java","-jar","/demo.jar"]
My docker compose file
# Docker Compose file Reference (https://docs.docker.com/compose/compose-file/)
version: '3.7'
# Define services
services:
# App backend service
app-server:
# Configuration for building the docker image for the backend service
build:
context: . # Use an image built from the specified dockerfile in the `polling-app-server` directory.
dockerfile: ./Dockerfile
container_name: empserver
ports:
- "3000:3000" # Forward the exposed port 8080 on the container to port 8080 on the host machine
restart: always
depends_on:
- db # This service depends on mysql. Start that first.
environment: # Pass environment variables to the service
SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/employee_entries?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root
# Database Service (Mysql)
db:
image: mysql:5.7
ports:
- "3306:3306"
restart: always
environment:
MYSQL_DATABASE: employee_entries
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
My docker net works
NETWORK ID NAME DRIVER SCOPE
b95e3d99b266 Default Switch ics local
7fff4f9713f8 demo_default nat local
fe8883b77d1d emp-mysql ics local
f464aab9064a nat nat local
a5bd5e8efe61 none null local
App is successfully running using java -jar target\demo-0.0.1-SNAPSHOT.jar
but when I am doing docker-compose up
I got below error
app-server_1 | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
app-server_1 |
app-server_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
app-server_1 | at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_212]
app-server_1 | at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_212]
app-server_1 | at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_212]
app-server_1 | at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_212]
app-server_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | ... 56 common frames omitted
app-server_1 | Caused by: java.net.UnknownHostException: db
app-server_1 | at java.net.InetAddress.getAllByName0(InetAddress.java:1281) ~[na:1.8.0_212]
app-server_1 | at java.net.InetAddress.getAllByName(InetAddress.java:1193) ~[na:1.8.0_212]
app-server_1 | at java.net.InetAddress.getAllByName(InetAddress.java:1127) ~[na:1.8.0_212]
app-server_1 | at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | ... 59 common frames omitted
I am able to access mysql database and tables but from docker compose it was not
any suggestion would really be helpful
You need to provide the container names to the services and use them when referring them from each other. In your environment section for app-server, the url for database points to 127.0.0.1 but the database is not running on same container as app-server so this will fail.
To make this work, provide container names to services for eg : my_mysql and my_app-server and use it in environment url as jdbc:mysql://my_mysql:3306.
Please see the modified file below:
# Docker Compose file Reference (https://docs.docker.com/compose/compose-file/)
version: '3.7'
# Define services
services:
# App backend service
app-server:
# Configuration for building the docker image for the backend service
build:
context: . # Use an image built from the specified dockerfile in the `polling-app-server` directory.
dockerfile: ./Dockerfile
container_name: my_app-server
ports:
- "3000:3000" # Forward the exposed port 8080 on the container to port 8080 on the host machine
restart: always
depends_on:
- db # This service depends on mysql. Start that first.
environment: # Pass environment variables to the service
SPRING_DATASOURCE_URL: jdbc:mysql://my_mysql:3306/employee_entries?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root
# Database Service (Mysql)
db:
image: mysql:5.7
container_name: my_mysql
ports:
- "3306:3306"
restart: always
environment:
MYSQL_DATABASE: employees
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
network:
my-network:

Springboot mongo docker-compose fail to connect

My docker-compose.yml is as shown
version: '3'
services:
backend-service:
image: 'storio-360-service:v1.0'
build: .
container_name: storio-360-service
ports:
- 8090:8080
depends_on:
- db_mongo
links:
- db_mongo
db_mongo:
image: 'mongo'
container_name: db_mongo
ports:
- 27018:27017
volumes:
- /home/bob/Bob/data:/data/db
restart: always
My Dockerfile is
FROM openjdk:8u111-jdk-alpine
VOLUME /tmp
ADD /target/backend-service-1.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
CMD curl "db_mongo:27018"
Because of this set up, my repository in my spring has this code
#Repository
public class WatcherRepository {
private MongoOperations mongoOps;
#Autowired
public WatcherRepository() {
String myHost = "db_mongo";
this.mongoOps = new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(myHost), MongoConstant.DATABASE_NAME));
}
// Other code to access the mongo db
}
However, when i run docker-compose up --build,
I get the following when Spring boot is starting up,
02:24:55.871 [main] INFO org.mongodb.driver.cluster - Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
storio-360-service | 02:24:55.923 [cluster-ClusterId{value='5d3faa779470450001317225', description='null'}-localhost:27017] INFO org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017
storio-360-service | com.mongodb.MongoSocketOpenException: Exception opening socket
storio-360-service | at com.mongodb.connection.SocketStream.open(SocketStream.java:62)
storio-360-service | at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
storio-360-service | at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114)
storio-360-service | at java.lang.Thread.run(Thread.java:745)
storio-360-service | Caused by: java.net.ConnectException: Connection refused (Connection refused)
storio-360-service | at java.net.PlainSocketImpl.socketConnect(Native Method)
storio-360-service | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
storio-360-service | at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
storio-360-service | at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
storio-360-service | at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
storio-360-service | at java.net.Socket.connect(Socket.java:589)
storio-360-service | at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:59)
storio-360-service | at com.mongodb.connection.SocketStream.open(SocketStream.java:57)
storio-360-service | ... 3 common frames omitted
storio-360-service | 02:24:56.060 [main] INFO org.mongodb.driver.cluster - Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500
Then Spring boot will shown that it is waiting for calls as it sets up successfully.
02:34:39.274 [main] INFO o.d.i.i.storio.service.Service - Started Service in 5.353 seconds (JVM running for 6.085)
However, when i make the api call which will call the mongodb, it shows me the error
Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
I am new to Docker and it is clear that my springboot cannot access mongo. What am i doing wrong in my Dockerfile or docker-compose? thanks
Looks like you are forwarding your mongodb port to 27018
- 27018:27017
and you haven't specified 27018 in Spring config.
Hence Spring boot by default tries to connect to 27017
Solution:
Either remove the port forwarding, or update Spring Boot config to use mongo at 27018
Update:
Here are some Spring Boot's mongo auto configuration tips for the OP.
Have dependency on a mongodb starter for spring boot
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
Provide Mongo DB details in application properties.
spring.data.mongodb.database= # Database name.
spring.data.mongodb.host= # Mongo server host. Cannot be set with URI.
spring.data.mongodb.password= # Login password of the mongo server. Cannot be set with URI.
spring.data.mongodb.port= # Mongo server port. Cannot be set with URI.
spring.data.mongodb.username= # Login user of the mongo server. Cannot be set with URI
(Here the OP needs to specify his mongodb host and port)
Now, the only thing left is to autowire MongoTemplate, where ever you want to use.
#Autowired
private MongoTemplate mongoTemplate;

Run "apereo/cas" docker image prints "Failed to start connector" error

My goal is to run CAS to replace ADFS. I thought starting with the docker image is a good place to begin.
I've tried running two different versions of apereo/cas and both have the same error.
Here's what I tried.
command
docker run -p 8080:8080 -p 8443:8443 apereo/cas:v5.3.2
output
__ ____ _ ____ __
/ / / ___| / \ / ___| \ \
| | | | / _ \ \___ \ | |
| | | |___ / ___ \ ___) | | |
| | \____| /_/ \_\ |____/ | |
\_\ /_/
CAS Version: 5.3.2
CAS Commit Id: 145d8c3dd5e27333dd05f5cc10987df4656fba5e
CAS Build Date/Time: 2018-07-30T21:09:46Z
Spring Boot Version: 1.5.14.RELEASE
Spring Version: 4.3.18.RELEASE
Java Home: /opt/zulu8.30.0.1-jdk8.0.172-linux_x64/jre
Java Vendor: Azul Systems, Inc.
Java Version: 1.8.0_172
JVM Free Memory: 24 MB
JVM Maximum Memory: 539 MB
JVM Total Memory: 52 MB
JCE Installed: Yes
Node Version: N/A
NPM Version: N/A
OS Architecture: amd64
OS Name: Linux
OS Version: 4.9.87-linuxkit-aufs
OS Date/Time: 2018-08-30T13:18:59.269
OS Temp Directory: /tmp
------------------------------------------------------------
Apache Tomcat Version: Apache Tomcat/8.5.32
------------------------------------------------------------
2018-08-30 13:18:59,416 INFO [org.apereo.cas.configuration.DefaultCasConfigurationPropertiesSourceLocator] - <Configuration directory [/etc/cas/config] is not a directory or cannot be found at the specific path>
2018-08-30 13:18:59,470 INFO [org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration] - <Located property source: CompositePropertySource [name='casCompositePropertySource', propertySources=[PropertiesPropertySource {name='embeddedYamlOverriddenProperties'}]]>
2018-08-30 13:18:59,500 INFO [org.apereo.cas.web.CasWebApplication] - <The following profiles are active: standalone>
2018-08-30 13:18:59,674 INFO [org.apereo.cas.web.CasWebApplicationContext] - <Refreshing CasWebApplicationContext()>
2018-08-30 13:19:09,553 WARN [org.apereo.cas.config.CasCoreTicketsConfiguration] - <Runtime memory is used as the persistence storage for retrieving and managing tickets. Tickets that are issued during runtime will be LOST when the web server is restarted. This MAY impact SSO functionality.>
2018-08-30 13:19:09,557 INFO [org.apereo.cas.util.CoreTicketUtils] - <Ticket registry encryption/signing is turned off. This MAY NOT be safe in a clustered production environment. Consider using other choices to handle encryption, signing and verification of ticket registry tickets, and verify the chosen ticket registry does support this behavior.>
2018-08-30 13:19:36,081 INFO [org.apereo.cas.config.CasConfigurationSupportUtilitiesConfiguration] - <CAS is configured to NOT watch configuration directory [/etc/cas/config]. Changes require manual reloads/restarts.>
2018-08-30 13:19:37,111 WARN [org.apereo.cas.config.support.authentication.AcceptUsersAuthenticationEventExecutionPlanConfiguration] - <>
2018-08-30 13:19:37,128 WARN [org.apereo.cas.config.support.authentication.AcceptUsersAuthenticationEventExecutionPlanConfiguration] - <
____ _____ ___ ____ _
/ ___| |_ _| / _ \ | _ \ | |
\___ \ | | | | | | | |_) | | |
___) | | | | |_| | | __/ |_|
|____/ |_| \___/ |_| (_)
CAS is configured to accept a static list of credentials for authentication. While this is generally useful for demo purposes, it is STRONGLY recommended that you DISABLE this authentication method (by setting 'cas.authn.accept.users' to a blank value) and switch to a mode that is more suitable for production.>
2018-08-30 13:19:37,129 WARN [org.apereo.cas.config.support.authentication.AcceptUsersAuthenticationEventExecutionPlanConfiguration] - <>
2018-08-30 13:19:50,183 INFO [org.apereo.cas.support.events.listener.CasConfigurationEventListener] - <Refreshing CAS configuration. Stand by...>
2018-08-30 13:19:51,182 WARN [org.apereo.cas.config.CasCoreServicesConfiguration] - <Runtime memory is used as the persistence storage for retrieving and persisting service definitions. Changes that are made to service definitions during runtime WILL be LOST when the web server is restarted. Ideally for production, you need to choose a storage option (JDBC, etc) to store and track service definitions.>
2018-08-30 13:19:51,278 INFO [org.apereo.cas.services.AbstractServicesManager] - <Loaded [0] service(s) from [InMemoryServiceRegistry].>
2018-08-30 13:19:51,931 WARN [org.apereo.cas.util.cipher.BaseStringCipherExecutor] - <Secret key for encryption is not defined for [Ticket-granting Cookie]; CAS will attempt to auto-generate the encryption key>
2018-08-30 13:19:51,956 WARN [org.apereo.cas.util.cipher.BaseStringCipherExecutor] - <Generated encryption key [eTqXF8ggwLZtTQEZCskBylE0S4px3iBbGcverLvO2Fs] of size [256] for [Ticket-granting Cookie]. The generated key MUST be added to CAS settings under setting [cas.tgc.crypto.encryption.key].>
2018-08-30 13:19:51,961 WARN [org.apereo.cas.util.cipher.BaseStringCipherExecutor] - <Secret key for signing is not defined for [Ticket-granting Cookie]. CAS will attempt to auto-generate the signing key>
2018-08-30 13:19:51,973 WARN [org.apereo.cas.util.cipher.BaseStringCipherExecutor] - <Generated signing key [ZJNEO4PuSX3og9E923KKcp6bVVHb7bajkqkP1B4_35ytg4rW5CPqRvFYuxzmBTHAvsaTnBRvKqe53F_4ulg5Rw] of size [512] for [Ticket-granting Cookie]. The generated key MUST be added to CAS settings under setting [cas.tgc.crypto.signing.key].>
2018-08-30 13:19:53,293 WARN [org.apereo.cas.util.cipher.BaseBinaryCipherExecutor] - <Secret key for signing is not defined under [cas.webflow.crypto.signing.key]. CAS will attempt to auto-generate the signing key>
2018-08-30 13:19:53,295 WARN [org.apereo.cas.util.cipher.BaseBinaryCipherExecutor] - <Generated signing key [txKypaRUGM0NyMfI9reKAPzMCEuTDO4xWh9J-G16rmp5l-ZWpqBR7bge1wPvAx0FdYw2j__4aI_6Q9qANFe5ng] of size [512]. The generated key MUST be added to CAS settings under setting [cas.webflow.crypto.signing.key].>
2018-08-30 13:19:53,297 WARN [org.apereo.cas.util.cipher.BaseBinaryCipherExecutor] - <Secret key for encryption is not defined under [cas.webflow.crypto.encryption.key]. CAS will attempt to auto-generate the encryption key>
2018-08-30 13:19:53,300 WARN [org.apereo.cas.util.cipher.BaseBinaryCipherExecutor] - <Generated encryption key [xUiptRY2-RuCvAFV39UJlg] of size [16]. The generated key MUST be added to CAS settings under setting [cas.webflow.crypto.encryption.key].>
2018-08-30 13:19:53,867 ERROR [org.apache.catalina.core.StandardService] - <Failed to start connector [Connector[HTTP/1.1-8443]]>
org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-8443]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-catalina-8.5.32.jar!/:8.5.32]
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) ~[tomcat-catalina-8.5.32.jar!/:8.5.32]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:265) ~[spring-boot-1.5.14.RELEASE.jar!/:1.5.14.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:208) ~[spring-boot-1.5.14.RELEASE.jar!/:1.5.14.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297) ~[spring-boot-1.5.14.RELEASE.jar!/:1.5.14.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145) ~[spring-boot-1.5.14.RELEASE.jar!/:1.5.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-4.3.18.RELEASE.jar!/:4.3.18.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.14.RELEASE.jar!/:1.5.14.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) ~[spring-boot-1.5.14.RELEASE.jar!/:1.5.14.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) ~[spring-boot-1.5.14.RELEASE.jar!/:1.5.14.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.14.RELEASE.jar!/:1.5.14.RELEASE]
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134) ~[spring-boot-1.5.14.RELEASE.jar!/:1.5.14.RELEASE]
at org.apereo.cas.web.CasWebApplication.main(CasWebApplication.java:71) ~[cas-server-webapp-init-5.3.2.jar!/:5.3.2]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_172]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_172]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_172]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_172]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[cas.war:?]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[cas.war:?]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[cas.war:?]
at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59) ~[cas.war:?]
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1020) ~[tomcat-catalina-8.5.32.jar!/:8.5.32]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-catalina-8.5.32.jar!/:8.5.32]
... 20 more
Caused by: java.lang.IllegalArgumentException: No aliases for private keys found in key store
at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:116) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:87) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:225) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1150) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:591) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1018) ~[tomcat-catalina-8.5.32.jar!/:8.5.32]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-catalina-8.5.32.jar!/:8.5.32]
... 20 more
Caused by: java.io.IOException: No aliases for private keys found in key store
at org.apache.tomcat.util.net.jsse.JSSEUtil.getKeyManagers(JSSEUtil.java:233) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:114) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:87) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:225) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1150) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:591) ~[tomcat-coyote-8.5.32.jar!/:8.5.32]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1018) ~[tomcat-catalina-8.5.32.jar!/:8.5.32]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-catalina-8.5.32.jar!/:8.5.32]
... 20 more
I also tried a different version with no luck.
docker run -p 8080:8080 -p 8443:8443 apereo/cas:v5.2.2
This appears to be a problem with missing keys that I (think) need to be generated but I'm not sure if/where I need to mount a volume or what to do next.
FILE: /etc/cas/config/
keytool -genkeypair -alias cas -keyalg RSA \
-keypass changeit -storepass changeit \
-keystore $AP_HOME/etc/cas/thekeystore \
-dname "CN=localhost.xxx.com.tw,OU=xxx,OU=xxx,C=TW" \
-ext SAN="dns:localhost,ip:127.0.0.1,dns:`hostname`"
copy this file into container docker:
docker cp /etc/cas/thekeystore *container_name*:/etc/cas
I'd like to map the etc outside container, but maintains in container.
~/etc/cas/theKeystore
~/etc/cas/config/application.properties
~/etc/cas/config/cas.properties
~/etc/cas/config/log4j2.xml
~/cas-overlay: clone from github.
Try this
docker --name ...
-p 8443:8443 -p ...
-v ~/etc/cas:/etc/cas
-v ~/cas-overlay:/cas-overlay
...
I also maintain my project out of container.
such as modifing ~/etc/cas/config/application.properties, ...
and/or rebuilding cas.war, in ~/cas-overlay/mvnm package.
then restart this container dokcer.

Resources