docker compose with services and mongo databases throws error opening socket - java

I've two services, these are application.yml's:
category-service -> application.yml
spring:
application:
name: category-service
data:
mongodb:
host: categoriesdb
port: 27017
database: categoriesdb
server:
port: 8081
productcatalog-service -> application.yml
spring:
application:
name: productcatalog-service
data:
mongodb:
host: productsdb
port: 27018
database: productsdb
server:
port: 8080
And docker-compose:
version: "3.8"
services:
productcatalog-service:
container_name: productcatalog-service
image: productcatalog-service
build:
./productcatalog-service
ports:
- 8080:8080
links:
- productsdb
category-service:
container_name: category-service
image: category-service
build:
./category-service
ports:
- 8081:8081
links:
- categoriesdb
categoriesdb:
container_name: categoriesdb
image: mongo:latest
volumes:
- ./data/categories-db:/data/db"
ports:
- 27017:27017
productsdb:
container_name: productsdb
image: mongo:latest
volumes:
- ./data/products-db:/data/db
ports:
- 27018:27017
And I've a problem with running, because I get after docker-compose up:
productcatalog-service | at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.1.1.jar!/:na]
productcatalog-service | at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
productcatalog-service | Caused by: java.net.UnknownHostException: productsdb: Name or service not known
productcatalog-service | at java.base/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:932) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1517) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:851) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1507) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1366) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1300) ~[na:na]
productcatalog-service | at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203) ~[mongodb-driver-core-4.1.1.jar!/:na]
productcatalog-service | ... 6 common frames omitted
productcatalog-service |
category-service | 2020-12-05 23:41:05.335 INFO 1 --- [127.0.0.1:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 127.0.0.1:27017
category-service |
category-service | com.mongodb.MongoSocketOpenException: Exception opening socket
category-service | at com.mongodb.internal.connection.AsynchronousSocketChannelStream$OpenCompletionHandler.failed(AsynchronousSocketChannelStream.java:124) ~[mongodb-driver-core-4.1.1.jar!/:na]
category-service | at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:129) ~[na:na]
category-service | at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:285) ~[na:na]
category-service | at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(UnixAsynchronousSocketChannelImpl.java:200) ~[na:na]
category-service | at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(UnixAsynchronousSocketChannelImpl.java:215) ~[na:na]
category-service | at java.base/sun.nio.ch.EPollPort$EventHandlerTask.run(EPollPort.java:306) ~[na:na]
category-service | at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) ~[na:na]
category-service | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
category-service | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
category-service | at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
category-service | Caused by: java.net.ConnectException: Connection refused
category-service | at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.checkConnect(Native Method) ~[na:na]
category-service | at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:254) ~[na:na]
To sum up, I'd like to run these two services using one docker-compose, each service could have one mongodb assigned to it. If my thoughts about architecture are wrong, please correct me.
Thank you for help!

it seems productsdb needs change:
productsdb:
container_name: productsdb
image: mongo:latest
volumes:
- ./data/products-db:/data/db
ports:
- 27018:27018

if you use spring boot 2.4.0 try to downgrade version to 2.3.5

Related

Can't connect JBPM service to Postgress service, both are using the same container

I am using this docker - compose.yml.
services:
postgres:
image: postgres:14.3-alpine
volumes:
- C:\Postgres:/var/lib/postgresql/data
environment:
POSTGRES_DB: jbpm
POSTGRES_USER: jbpm
POSTGRES_PASSWORD: jbpm
ports:
- 5432:5432
jbpm:
image: quay.io/kiegroup/jbpm-server-full
environment:
JBPM_DB_DRIVER: postgres
JBPM_DB_HOST: postgres
ports:
- 8080:8080
- 8001:8081
depends_on:
- postgres
But i keep receiving the message error:
| 23:15:58,475 INFO [io.jaegertracing.internal.reporters.RemoteReporter] (jaeger.RemoteReporter-QueueProcessor) FlushCommand is working again!
jbpm_1 | 23:16:07,477 WARN [io.jaegertracing.internal.reporters.RemoteReporter] (jaeger.RemoteReporter-QueueProcessor) FlushCommand execution failed! Repeated errors of this command will not be logged.: io.jaegertracing.internal.exceptions.SenderException: Failed to flush spans.
jbpm_1 | at io.jaegertracing.jaeger#1.5.0//io.jaegertracing.thrift.internal.senders.ThriftSender.flush(ThriftSender.java:115)
jbpm_1 | at io.jaegertracing.jaeger#1.5.0//io.jaegertracing.internal.reporters.RemoteReporter$FlushCommand.execute(RemoteReporter.java:160)
jbpm_1 | at io.jaegertracing.jaeger#1.5.0//io.jaegertracing.internal.reporters.RemoteReporter$QueueProcessor.run(RemoteReporter.java:182)
jbpm_1 | at java.base/java.lang.Thread.run(Thread.java:834)
jbpm_1 | Caused by: io.jaegertracing.internal.exceptions.SenderException: Could not send 1 spans
jbpm_1 | at io.jaegertracing.jaeger#1.5.0//io.jaegertracing.thrift.internal.senders.UdpSender.send(UdpSender.java:85)
jbpm_1 | at io.jaegertracing.jaeger#1.5.0//io.jaegertracing.thrift.internal.senders.ThriftSender.flush(ThriftSender.java:113)
jbpm_1 | ... 3 more
jbpm_1 | Caused by: org.apache.thrift.transport.TTransportException: Cannot flush closed transport
jbpm_1 | at io.jaegertracing.jaeger#1.5.0//io.jaegertracing.thrift.internal.reporters.protocols.ThriftUdpTransport.flush(ThriftUdpTransport.java:148)
jbpm_1 | at org.apache.thrift#0.13.0//org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:73)
jbpm_1 | at org.apache.thrift#0.13.0//org.apache.thrift.TServiceClient.sendBaseOneway(TServiceClient.java:66)
jbpm_1 | at io.jaegertracing.jaeger#1.5.0//io.jaegertracing.agent.thrift.Agent$Client.send_emitBatch(Agent.java:70)
jbpm_1 | at io.jaegertracing.jaeger#1.5.0//io.jaegertracing.agent.thrift.Agent$Client.emitBatch(Agent.java:63)
jbpm_1 | at io.jaegertracing.jaeger#1.5.0//io.jaegertracing.thrift.internal.senders.UdpSender.send(UdpSender.java:83)
jbpm_1 | ... 4 more
jbpm_1 | Caused by: java.net.PortUnreachableException: ICMP Port Unreachable
jbpm_1 | at java.base/java.net.PlainDatagramSocketImpl.send(Native Method)
jbpm_1 | at java.base/java.net.DatagramSocket.send(DatagramSocket.java:695)
jbpm_1 | at io.jaegertracing.jaeger#1.5.0//io.jaegertracing.thrift.internal.reporters.protocols.ThriftUdpTransport.flush(ThriftUdpTransport.java:146)
jbpm_1 | ... 9 more
jbpm_1 |
jbpm_1 | 23:16:08,477 IN
The documentation can be found in https://www.jbpm.org/learn/gettingStartedUsingDocker.html. And some examples in https://github.com/jboss-dockerfiles/business-central/tree/main/docker-compose-examples.
Can you help me? I have been trying several suggestions but none works.
If you don't use it in standalone.xml, You can disable this by remove :
<subsystem xmlns="urn:wildfly:microprofile-opentracing-smallrye:3.0" default-tracer="jaeger">
<jaeger-tracer name="jaeger">
<sampler-configuration sampler-type="const" sampler-param="1.0"/>
</jaeger-tracer>

Why I have a connection refused error when starting rabbit by docker-compose?

I run sprinboot app, front (in react), database and rabbitmq in docker-compose. When I run it everything works except rabbitmq. I had an error - "Connection refused".
docker-compose:
version: '3'
services:
server:
build: ./mlogger
ports:
- "8000:8080"
depends_on:
- database
restart: always
web:
build: ./web
ports:
- "4000:3000"
tty: true
depends_on:
- server
database:
container_name: 'mysql'
image: mysql
environment:
MYSQL_ROOT_PASSWORD: jitsi1234
MYSQL_USER: jitsiteam
MYSQL_DATABASE: testmlogger
ports:
- "3306:3306"
restart: always
rabbitmq:
image: rabbitmq:3-management
container_name: rabbitmq
command: sh -c "rabbitmq-plugins enable rabbitmq_auth_backend_ldap"
ports:
- "5672:5672"
- "15672:15672"
restart: always
error:
server_1 | 2020-09-05 16:14:42.110 INFO 6 --- [ntContainer#0-1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
server_1 | 2020-09-05 16:14:42.117 ERROR 6 --- [ntContainer#0-1] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).
server_1 |
server_1 | org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
server_1 | at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:61) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:524) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:751) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:214) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2089) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2062) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2042) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueInfo(RabbitAdmin.java:407) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:391) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.attemptDeclarations(AbstractMessageListenerContainer.java:1836) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1817) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1349) [spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1195) [spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_265]
server_1 | Caused by: java.net.ConnectException: Connection refused (Connection refused)
server_1 | at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_265]
server_1 | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_265]
server_1 | at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_265]
server_1 | at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_265]
server_1 | at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_265]
server_1 | at java.net.Socket.connect(Socket.java:607) ~[na:1.8.0_265]
server_1 | at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.9.0.jar!/:5.9.0]
server_1 | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1137) ~[amqp-client-5.9.0.jar!/:5.9.0]
server_1 | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1087) ~[amqp-client-5.9.0.jar!/:5.9.0]
server_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connectAddresses(AbstractConnectionFactory.java:560) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connect(AbstractConnectionFactory.java:533) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:487) ~[spring-rabbit-2.2.7.RELEASE.jar!/:2.2.7.RELEASE]
server_1 | ... 12 common frames omitted
Spring boot properties:
spring.rabbitmq.address=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
I'm using ldap also, and I want to add users to rabbitmq on start. I can do it by adding commands to docker-compose?
Spring boot ldap config:
#Configuration
#EnableLdapRepositories
public class LdapConfig {
#Bean
public LdapContextSource contextSource() {
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://localhost:18889");
contextSource.setBase("dc=example,dc=com");
return contextSource;
}
#Bean
public LdapTemplate ldapTemplate() {
return new LdapTemplate(contextSource());
}
}
I figured it out, in the docker compose part responsible for the spring application, I had to specify the network mode:
server:
build: ./mlogger
ports:
- "8000:8080"
depends_on:
- database
- rabbitmq
network_mode: "host"
Inside a container, localhost is the container itself, not the host it is running on. Components are visible to each other with their service names. Insead of connecting to localhost:5672, connect to rabbitmq:5672, and it should work. Do the same for the database as well.

Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections

I'm getting the below error while giving docker-compose up.
springbootapp | 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.
springbootapp | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:280) ~[postgresql-42.2.8.jar!/:42.2.8]
springbootapp | at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.8.jar!/:42.2.8]
springbootapp | at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195) ~[postgresql-42.2.8.jar!/:42.2.8]
springbootapp | at org.postgresql.Driver.makeConnection(Driver.java:458) ~[postgresql-42.2.8.jar!/:42.2.8]
springbootapp | at org.postgresql.Driver.connect(Driver.java:260) ~[postgresql-42.2.8.jar!/:42.2.8]
springbootapp | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.2.jar!/:na]
springbootapp | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:354) ~[HikariCP-3.4.2.jar!/:na]
springbootapp | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:202) ~[HikariCP-3.4.2.jar!/:na]
springbootapp | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473) [HikariCP-3.4.2.jar!/:na]
springbootapp | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:554) [HikariCP-3.4.2.jar!/:na]
springbootapp | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-3.4.2.jar!/:na]
springbootapp | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) [HikariCP-3.4.2.jar!/:na]
springbootapp | at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56) [flyway-core-6.0.8.jar!/:na]
springbootapp | at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:80) [flyway-core-6.0.8.jar!/:na]
springbootapp | at org.flywaydb.core.Flyway.execute(Flyway.java:438) [flyway-core-6.0.8.jar!/:na]
springbootapp | at org.flywaydb.core.Flyway.migrate(Flyway.java:149) [flyway-core-6.0.8.jar!/:na]
springbootapp | at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65) [spring-boot-autoconfigure-2.2.6.RELEASE.jar!/:2.2.6.RELEASE]
Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
EXPOSE 8082
RUN mkdir -p /app/
RUN mkdir -p /app/logs/
ADD target/household-0.0.1-SNAPSHOT.jar /app/app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=container", "-jar", "/app/app.jar"]
docker-compose.yml:
version: '3.2'
services:
postgres:
image: postgres:latest
network_mode: bridge
container_name: postgres
volumes:
- postgres-data:/var/lib/postgresql/data
expose:
- 5432
ports:
- 5434:5434
environment:
- POSTGRES_PASSWORD=
- POSTGRES_USER=
- POSTGRES_DB=test
restart: unless-stopped
# APP*****
springbootapp:
image: springbootapp:latest
network_mode: bridge
container_name: springbootapp
expose:
- 8080
ports:
- 8080:8080
restart: unless-stopped
depends_on:
- postgres
links:
- postgres
volumes:
postgres-data:
The error is definitely due to postgres is not running correctly or the app is not able to communicate to postgres. Use below docker-compose file and check.
version: '2'
services:
postgresql:
image: postgres:10.4
volumes:
- ./postgresql/:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=someuser
- POSTGRES_PASSWORD=
ports:
- 5432:5432
You can always use following command to check if db is accepting connection.
psql -h [HostIP] -U [db_user] -d [db_name]
I had same problem. the solution is simple.
first open docker app,
in Terminal process;
then you have to go to the directory where the docker-compose.yml
file is located.
then write docker-compose up
next, open pgAdmin app and choose db to your spring project,
next, enter the password and username found in docker-compose.yml
(username: image, password: POSTGRES_PASSWORD),
finally run the spring boot project.

Spring Boot and MySQL can't connect on Docker while using docker-compose - Shows "Failed to create/setup connection: Communications link failure"

I'm just trying to setup a starter project based on Spring Boot and MySQL using Docker. So I tried to run this github project on the Docker. But I am unable to establish connection between Java and MySQL.
I'm running Ubuntu 16.04.
I'm getting "Failed to create/setup connection: Communications link failure...." error while executing "docker-compose up" command.
Also this error doesn't show up if I use Docker Client. Like when I do as:
# 1. docker run -d -p 6033:3306 --name=docker-mysql --env="MYSQL_ROOT_PASSWORD=root" --env="MYSQL_PASSWORD=root" --env="MYSQL_DATABASE=book_manager" mysql
# 2. docker build -t springio/gs-spring-boot-docker .
# 3. docker run -t --link docker-mysql:mysql -p 10222:10222 springio/gs-spring-boot-docker
I tried to setup same environment through docker-compose but somehow its not working.
Below are the configuration details:
application.properties
logging.level.org.springframework=INFO
logging.level.com.mkyong=INFO
logging.level.com.zaxxer=DEBUG
logging.level.root=ERROR
logging.pattern.console=%-5level %logger{36} - %msg%n
## MySQL
spring.datasource.url=jdbc:mysql://docker-mysql:3306/book_manager
spring.datasource.username=root
spring.datasource.password=root
server.port=10222
connection.driver.class = com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQLDialect
#`hibernate_sequence' doesn't exist
spring.jpa.hibernate.use-new-id-generator-mappings=false
hibernate.show_sql=false
#drop n create table again, good for testing, comment this in production
spring.jpa.hibernate.ddl-auto=create
Dockerfile for the java application container (service)
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} spring-data-jpa-mysql-1.0.jar
ENTRYPOINT ["java","-jar","/spring-data-jpa-mysql-1.0.jar"]
docker-compose.yml
version: '3'
services:
docker-mysql:
restart: always
container_name: docker-mysql
image: mysql
environment:
MYSQL_DATABASE: book_manager
MYSQL_ROOT_PASSWORD: root
ports:
- "6033:3306"
networks:
- spring-boot-mysql-network
book-manager-app:
build:
context: ./
dockerfile: Dockerfile
expose:
- "10222"
ports:
- "10222:10222"
depends_on:
- "docker-mysql"
networks:
- spring-boot-mysql-network
networks:
spring-boot-mysql-network:
driver: bridge
The following is the error log that I'm getting:
$/spring-data-jpa-mysql-compose$ docker-compose up
Creating network "spring-data-jpa-mysql-compose_spring-boot-mysql-network" with driver "bridge"
Creating docker-mysql ... done
Creating spring-data-jpa-mysql-compose_book-manager-app_1 ... done
Attaching to docker-mysql, spring-data-jpa-mysql-compose_book-manager-app_1
docker-mysql | 2020-04-07 13:44:39+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
docker-mysql | 2020-04-07 13:44:39+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
docker-mysql | 2020-04-07 13:44:39+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
docker-mysql | 2020-04-07 13:44:39+00:00 [Note] [Entrypoint]: Initializing database files
docker-mysql | 2020-04-07T13:44:39.855069Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
docker-mysql | 2020-04-07T13:44:39.855190Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 42
book-manager-app_1 |
book-manager-app_1 | . ____ _ __ _ _
book-manager-app_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
book-manager-app_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
book-manager-app_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
book-manager-app_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
book-manager-app_1 | =========|_|==============|___/=/_/_/_/
book-manager-app_1 | :: Spring Boot :: (v2.1.2.RELEASE)
book-manager-app_1 |
book-manager-app_1 | INFO com.mkyong.StartApplication - Starting StartApplication v1.0 on 3638e84181ae with PID 1 (/spring-data-jpa-mysql-1.0.jar started by root in /)
book-manager-app_1 | INFO com.mkyong.StartApplication - No active profile set, falling back to default profiles: default
book-manager-app_1 | INFO o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data repositories in DEFAULT mode.
book-manager-app_1 | INFO o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 134ms. Found 1 repository interfaces.
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - Driver class com.mysql.cj.jdbc.Driver found in Thread context class loader org.springframework.boot.loader.LaunchedURLClassLoader#5d099f62
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration:
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - allowPoolSuspension.............false
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - autoCommit......................true
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - catalog.........................none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - connectionInitSql...............none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - connectionTestQuery.............none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - connectionTimeout...............30000
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - dataSource......................none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - dataSourceClassName.............none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - dataSourceProperties............{password=<masked>}
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - driverClassName................."com.mysql.cj.jdbc.Driver"
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - healthCheckProperties...........{}
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - healthCheckRegistry.............none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - idleTimeout.....................600000
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl.........................jdbc:mysql://docker-mysql:3306/book_manager
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................10
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - minimumIdle.....................10
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked>
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - poolName........................"HikariPool-1"
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - readOnly........................false
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - schema..........................none
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - transactionIsolation............default
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - username........................"root"
book-manager-app_1 | DEBUG com.zaxxer.hikari.HikariConfig - validationTimeout...............5000
book-manager-app_1 | INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
book-manager-app_1 | DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Failed to create/setup connection: Communications link failure
book-manager-app_1 |
book-manager-app_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
book-manager-app_1 | DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Cannot acquire connection from data source
book-manager-app_1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
book-manager-app_1 |
book-manager-app_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
book-manager-app_1 | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
book-manager-app_1 | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
book-manager-app_1 | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
book-manager-app_1 | at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
book-manager-app_1 | at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
book-manager-app_1 | at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
book-manager-app_1 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136)
book-manager-app_1 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)
book-manager-app_1 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)
book-manager-app_1 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)
book-manager-app_1 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)
book-manager-app_1 | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
book-manager-app_1 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
book-manager-app_1 | at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157)
book-manager-app_1 | at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
book-manager-app_1 | at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
book-manager-app_1 | at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319)
book-manager-app_1 | at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356)
book-manager-app_1 | at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:73)
book-manager-app_1 | at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:142)
book-manager-app_1 | at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:112)
book-manager-app_1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$ff868e63.CGLIB$jpaVendorAdapter$8(<generated>)
book-manager-app_1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$ff868e63$$FastClassBySpringCGLIB$$5875e117.invoke(<generated>)
book-manager-app_1 | at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
book-manager-app_1 | at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
book-manager-app_1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$ff868e63.jpaVendorAdapter(<generated>)
book-manager-app_1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
book-manager-app_1 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
book-manager-app_1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
book-manager-app_1 | at java.lang.reflect.Method.invoke(Method.java:498)
book-manager-app_1 | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
book-manager-app_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
book-manager-app_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
book-manager-app_1 | at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
book-manager-app_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91)
book-manager-app_1 | at com.mysql.cj.NativeSession.connect(NativeSession.java:152)
book-manager-app_1 | at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955)
book-manager-app_1 | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
book-manager-app_1 | ... 83 common frames omitted
book-manager-app_1 | Caused by: java.net.ConnectException: Connection refused (Connection refused)
book-manager-app_1 | at java.net.PlainSocketImpl.socketConnect(Native Method)
book-manager-app_1 | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
book-manager-app_1 | at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
book-manager-app_1 | at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
book-manager-app_1 | at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
book-manager-app_1 | at java.net.Socket.connect(Socket.java:589)
book-manager-app_1 | at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)
book-manager-app_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
book-manager-app_1 | ... 86 common frames omitted
book-manager-app_1 | ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
book-manager-app_1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
book-manager-app_1 |
book-manager-app_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
book-manager-app_1 | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
book-manager-app_1 | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
book-manager-app_1 | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
book-manager-app_1 | at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
book-manager-app_1 | at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
book-manager-app_1 | at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
book-manager-app_1 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136)
book-manager-app_1 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)
book-manager-app_1 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)
book-manager-app_1 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)
book-manager-app_1 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)
book-manager-app_1 | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
book-manager-app_1 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
book-manager-app_1 | at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157)
book-manager-app_1 | at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
book-manager-app_1 | at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
book-manager-app_1 | at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319)
book-manager-app_1 | at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
book-manager-app_1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
book-manager-app_1 | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083)
book-manager-app_1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:853)
book-manager-app_1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
book-manager-app_1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
book-manager-app_1 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
book-manager-app_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
book-manager-app_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
book-manager-app_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
book-manager-app_1 | at com.mkyong.StartApplication.main(StartApplication.java:19)
book-manager-app_1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
book-manager-app_1 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
book-manager-app_1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
book-manager-app_1 | at java.lang.reflect.Method.invoke(Method.java:498)
book-manager-app_1 | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
book-manager-app_1 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
book-manager-app_1 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
book-manager-app_1 | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
book-manager-app_1 | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
book-org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
book-manager-app_1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
book-manager-app_1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
book-manager-app_1 | at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
book-manager-app_1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
book-manager-app_1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
book-manager-app_1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
book-manager-app_1 | at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMertiesSet(AbstractEntityManagerFactoryBean.java:377)
book-manager-app_1 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
book-manager-app_1 | at java.lang.reflect.Method.invoke(Method.java:498)
book-manager-app_1 | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
book-manager-app_1 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
book-manager-app_1 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
book-manager-app_1 | at com.cketImpl.java:392)
book-manager-app_1 | at java.net.Socket.connect(Socket.java:589)
book-manager-app_1 | at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)
book-manager-app_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
book-manager-app_1 | ... 59 common frames omitted
book-manager-app_1 | WARN o.s.c.a.AnnotationConfigApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
book-manager-app_1 | INFO o.s.b.a.l.ConditionEvaluationReportLoggingListener -
book-manager-app_1 |
book-manager-app_1 | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
book-manager-app_1 | ERROR o.s.boot.SpringApplication - Application run failed
book-manager-app_1 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstractorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:853)
book-manager-app_1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
book-manager-app_1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
book-manager-app_1 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
book-manager-app_1 | Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
book-manager-app_1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
book-manager-app_1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
book-manager-app_1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
book-manager-app_1 | at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentityManagerFactoryBuilderImpl.java:904)
book-manager-app_1 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935)
book-manager-app_1 | at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityMaAbstractEntityManagerFactoryBean.java:377)
book-manager-app_1 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804)
book-manager-app_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741)
book-manager-app_1 | ... 23 common frames omitted
book-manager-app_1 | Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
book-manager-app_1 | at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImporg.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94)
book-manager-app_1 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
book-manager-app_1 | ... 40 common frames omitted
spring-data-jpa-mysql-compose_book-manager-app_1 exited with code 1

Spring Boot cannot connect to MySQLand exits in Docker/Docker compose

Below is my application.properties file
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?autoReconnect=true
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
Below is my docker-compose.yml file
version: '3'
services:
docker-mysql:
image: mysql:latest
ports:
- 3306
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
- MYSQL_PASSWORD=root
spring-boot-jpa-docker-webapp:
image: springboot_docker
depends_on:
- docker-mysql
ports:
- 8080:8080
environment:
- DATABASE_HOST=docker-mysql
- DATABASE_USER=root
- DATABASE_PASSWORD=root
- DATABASE_NAME=test
- DATABASE_PORT=3306
Application is exited with
Caused by: java.net.ConnectException: Connection refused (Connection
refused)
Caused by: java.sql.SQLNonTransientConnectionException: Could not
create connection to database server. Attempted reconnect 3 times.
Giving up.
Caused by: java.net.ConnectException: Connection refused (Connection
refused)
git_spring-boot-jpa-docker-webapp_1 exited with code 1
Update 1: New error after correction to docker-compose
docker-mysql_1 | Initializing database
docker-mysql_1 | 2019-02-13T20:34:44.351044Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
docker-mysql_1 | 2019-02-13T20:34:44.351123Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.15) initializing of server in progress as process 29
docker-mysql_1 | 2019-02-13T20:34:44.352587Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
docker-mysql_1 | 2019-02-13T20:34:44.352592Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /var/lib/mysql/ is unusable. You can safely remove it.
docker-mysql_1 | 2019-02-13T20:34:44.352638Z 0 [ERROR] [MY-010119] [Server] Aborting
docker-mysql_1 | 2019-02-13T20:34:44.353948Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.15) MySQL Community Server - GPL.
spring-boot-jpa-docker-webapp_1 |
spring-boot-jpa-docker-webapp_1 | 2019-02-13 21:02:22.562 WARN 1 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 08001
spring-boot-jpa-docker-webapp_1 | 2019-02-13 21:02:22.562 ERROR 1 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Could not create connection to database server. Attempted reconnect 3 times. Giving up.
spring-boot-jpa-docker-webapp_1 | 2019-02-13 21:02:22.569 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
spring-boot-jpa-docker-webapp_1 | 2019-02-13 21:02:22.573 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
spring-boot-jpa-docker-webapp_1 | 2019-02-13 21:02:22.596 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :
spring-boot-jpa-docker-webapp_1 |
spring-boot-jpa-docker-webapp_1 | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
spring-boot-jpa-docker-webapp_1 | 2019-02-13 21:02:22.601 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
spring-boot-jpa-docker-webapp_1 |
spring-boot-jpa-docker-webapp_1 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
spring-boot-jpa-docker-webapp_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083) ~[spring-context-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:853) ~[spring-context-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
spring-boot-jpa-docker-webapp_1 | at com.github.Application.main(Application.java:15) ~[classes!/:1.0-SNAPSHOT]
spring-boot-jpa-docker-webapp_1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[spring-boot-docker-1.0.jar:1.0-SNAPSHOT]
spring-boot-jpa-docker-webapp_1 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[spring-boot-docker-1.0.jar:1.0-SNAPSHOT]
spring-boot-jpa-docker-webapp_1 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[spring-boot-docker-1.0.jar:1.0-SNAPSHOT]
spring-boot-jpa-docker-webapp_1 | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) ~[spring-boot-docker-1.0.jar:1.0-SNAPSHOT]
spring-boot-jpa-docker-webapp_1 | Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
spring-boot-jpa-docker-webapp_1 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:402) ~[spring-orm-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | ... 22 common frames omitted
spring-boot-jpa-docker-webapp_1 | Caused by: org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
spring-boot-jpa-docker-webapp_1 | at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:48) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:69) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.jdbcStatement(GenerationTargetToDatabase.java:77) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:53) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:241) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:144) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
spring-boot-jpa-docker-webapp_1 | ... 26 common frames omitted
spring-boot-jpa-docker-webapp_1 | Caused by: java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:905) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:830) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-jpa-docker-webapp_1 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-jpa-docker-webapp_1 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-jpa-docker-webapp_1 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-jpa-docker-webapp_1 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-jpa-docker-webapp_1 | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-jpa-docker-webapp_1 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.2.0.jar!/:na]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:43) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
spring-boot-jpa-docker-webapp_1 | ... 42 common frames omitted
spring-boot-jpa-docker-webapp_1 | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
spring-boot-jpa-docker-webapp_1 |
spring-boot-jpa-docker-webapp_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
spring-boot-jpa-docker-webapp_1 | at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.NativeSession.connect(NativeSession.java:152) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:849) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | ... 56 common frames omitted
spring-boot-jpa-docker-webapp_1 | Caused by: java.net.ConnectException: Connection refused (Connection refused)
spring-boot-jpa-docker-webapp_1 | at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.15.jar!/:8.0.15]
spring-boot-jpa-docker-webapp_1 | ... 58 common frames omitted
You are passing the DATABASE_HOST, DATABASE_PORT, DATABASE_NAME, DATABASE_USER and DATABASE_PASSWORD but you are not using it inside your app.
Update your properties like this. (Better if your create a profile so that you app runs outside of docker)
spring.datasource.url=jdbc:mysql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}?autoReconnect=true
spring.datasource.username=${DATABASE_USER}
spring.datasource.password=${DATABASE_PASSWORD}
If you really want to use localhost as your db_url. You can also use network_mode: "service:[service name]" property of docker compose. Only downside is that this property cannot be used with port property.
version: '3'
services:
docker-mysql:
image: mysql:latest
network_mode: "service:spring-boot-jpa-docker-webapp"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
- MYSQL_PASSWORD=root
spring-boot-jpa-docker-webapp:
image: springboot_docker
depends_on:
- docker-mysql
ports:
- 8080:8080
- 3306 #Add this only if you want to expose the mysql to outer world.
environment:
- DATABASE_USER=root
- DATABASE_PASSWORD=root
- DATABASE_NAME=test
And your properties file could look like
spring.datasource.url=jdbc:mysql://localhost:3306/${DATABASE_NAME}?autoReconnect=true
spring.datasource.username=${DATABASE_USER}
spring.datasource.password=${DATABASE_PASSWORD}
Containers in compose services can connect to other containers by using name, e.g. try to ping database container from spring-boot container.
Check if you can ping database container
docker-compose exec spring-boot-jpa-docker-webapp /bin/bash
once you are in the shell (You may have to install ping in spring-boot container for testing only apt-get install iputils-ping or yum install depending on image container is based on)
ping docker-mysql
if ping is successful then it means you can connect to database
replace database url in application.properties with
spring.datasource.url=jdbc:mysql://docker-mysql:3306/test?autoReconnect=true
Minimal Example for Mysql
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- "./volumes/database:/var/lib/mysql"
Try following docker-compose
version: "3.7"
services:
docker-mysql:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
volumes:
- "./volumes/database:/var/lib/mysql"
networks:
- spring_net
spring-boot-jpa-docker-webapp:
image: springboot_docker
ports:
- "8080:8080"
networks:
- spring_net
networks:
spring_net:

Categories