Docker Spring Boot with MySQL database, connection refused - mysql

I try to connect from my Spring Boot Container to a MySQL database but the connection breaks
This is my compose file.
version: "3.8"
services:
myapi:
image: myapi:local
container_name: myapi
build:
context: ./../
dockerfile: ./docker/Dockerfile
ports:
- 5000:5000
depends_on:
- mysql
environment:
- SERVER_PORT=5000
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/testdb
- SPRING_DATASOURCE_USERNAME=admindev
- SPRING_DATASOURCE_PASSWORD=admindev
- SPRING_DATASOURCE_DRIVER_CLASS_NAME=com.mysql.cj.jdbc.Driver
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
- SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.MySQL5InnoDBDialect
volumes:
- mysql-data:/var/lib/mysql
mysql:
image: mysql:8
container_name: mysql
restart: always
ports:
- 5001:3306
environment:
- MYSQL_ROOT_PASSWORD=1234
- MYSQL_USER=admindev
- MYSQL_PASSWORD=admindev
- MYSQL_DATABASE=testdb
volumes:
mysql-data:
driver: local
The MySQL container starts and it's waiting for connections.
The application also starts, but when it tries to connect to the DB it breaks.
I can't find anything wrong with the docker-compose file. I looked over the documentation and I saw that in the data source URL, I can even omit the port.
UPDATE
mysql container logs:
2021-03-05 13:20:21+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-03-05 13:20:21+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-03-05 13:20:21+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-03-05 13:20:21+00:00 [Note] [Entrypoint]: Initializing database files
2021-03-05T13:20:21.662023Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.23) initializing of server in progress as process 42
2021-03-05T13:20:21.675007Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-03-05T13:20:22.643221Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-03-05T13:20:24.871463Z 6 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2021-03-05 13:20:29+00:00 [Note] [Entrypoint]: Database files initialized
2021-03-05 13:20:29+00:00 [Note] [Entrypoint]: Starting temporary server
2021-03-05T13:20:29.854747Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.23) starting as process 87
2021-03-05T13:20:29.882866Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-03-05T13:20:30.177247Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-03-05T13:20:30.340904Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
2021-03-05T13:20:30.477364Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-03-05T13:20:30.477747Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-03-05T13:20:30.482566Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2021-03-05T13:20:30.505587Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.23' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2021-03-05 13:20:30+00:00 [Note] [Entrypoint]: Temporary server started.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2021-03-05 13:20:33+00:00 [Note] [Entrypoint]: Creating database thesis
2021-03-05 13:20:33+00:00 [Note] [Entrypoint]: Creating user admindev
2021-03-05 13:20:33+00:00 [Note] [Entrypoint]: Giving user admindev access to schema thesis
2021-03-05 13:20:33+00:00 [Note] [Entrypoint]: Stopping temporary server
2021-03-05T13:20:33.332383Z 13 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.23).
2021-03-05T13:20:35.763423Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.23) MySQL Community Server - GPL.
2021-03-05 13:20:36+00:00 [Note] [Entrypoint]: Temporary server stopped
2021-03-05 13:20:36+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2021-03-05T13:20:36.568558Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.23) starting as process 1
2021-03-05T13:20:36.580255Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-03-05T13:20:36.776157Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-03-05T13:20:36.885922Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2021-03-05T13:20:36.950707Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-03-05T13:20:36.950893Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-03-05T13:20:36.956239Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2021-03-05T13:20:36.971274Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.23' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
myapi container logs:
2021-03-05 13:23:09.481 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2021-03-05 13:23:09.566 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 74ms. Found 1 JPA repository interfaces.
2021-03-05 13:23:10.186 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#2eee3069' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-03-05 13:23:10.194 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-03-05 13:23:10.714 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 5000 (http)
2021-03-05 13:23:10.732 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-03-05 13:23:10.732 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
2021-03-05 13:23:10.828 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/api] : Initializing Spring embedded WebApplicationContext
2021-03-05 13:23:10.828 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2738 ms
2021-03-05 13:23:11.152 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-05 13:23:11.222 INFO 1 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-03-05 13:23:11.289 WARN 1 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-03-05 13:23:11.320 INFO 1 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.21.Final
2021-03-05 13:23:11.606 INFO 1 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2021-03-05 13:23:11.782 INFO 1 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-03-05 13:23:12.386 INFO 1 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#5649ec46, org.springframework.security.web.context.SecurityContextPersistenceFilter#3e598df9, org.springframework.security.web.header.HeaderWriterFilter#7f9e1534, org.springframework.web.filter.CorsFilter#78dc4696, org.springframework.security.web.authentication.logout.LogoutFilter#79b663b3, stefan.buciu.config.filter.AuthenticationFilter#502f8b57, stefan.buciu.config.filter.AuthorizationFilter#5652f555, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#99a65d3, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#6813a331, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#4fe01805, org.springframework.security.web.session.SessionManagementFilter#81ff872, org.springframework.security.web.access.ExceptionTranslationFilter#5f8890c2]
2021-03-05 13:23:13.038 ERROR 1 --- [ task-1] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.5.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358) ~[HikariCP-3.4.5.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-3.4.5.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477) ~[HikariCP-3.4.5.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560) ~[HikariCP-3.4.5.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.4.5.jar!/:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.4.5.jar!/:na]
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:176) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1224) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1255) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) ~[spring-orm-5.2.9.RELEASE.jar!/:5.2.9.RELEASE]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
my application.yml file:
spring:
datasource:
username: admindev
password: admindev
url: jdbc:mysql://localhost:3306/testdb
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
server:
port: 5000
servlet:
contextPath: /api
I also thought of attaching the Dockerfile:
FROM openjdk:11-jdk-slim
RUN mkdir -p /home/app
COPY ./target/*.jar /home/app/application.jar
WORKDIR /home/app
CMD ["java", "-jar", "application.jar"]
In the COPY command I used a star because there is only one *.jar produce by maven, and I didn't want to always change my Dockerfile when I change my version. That command works if there is only one file.
The artefacts are built using mvn package and I had no errors there, if I run myself the command: java -jar *.jar in the target dir, the server starts running without any problems.

Related

MySQL docker container receives SHUTDOWN command

everyone. I have noticed strange behavior during MySQL docker container startup. Basically I'm trying to run the following command
docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.29
but after that I see from the logs that container after successful startup suddenly receives SHUTDOWN command, and reinitialize database again
2022-07-25T19:33:26.423537Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29) MySQL Community Server - GPL.
Here is all the logs:
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-25 19:33:19+00:00 [Note] [Entrypoint]: Initializing database files
2022-07-25T19:33:19.770157Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.29) initializing of server in progress as process 42
2022-07-25T19:33:19.775554Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-25T19:33:20.037982Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-25T19:33:21.277581Z 6 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2022-07-25 19:33:23+00:00 [Note] [Entrypoint]: Database files initialized
2022-07-25 19:33:23+00:00 [Note] [Entrypoint]: Starting temporary server
2022-07-25T19:33:23.494658Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 91
2022-07-25T19:33:23.505604Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-25T19:33:23.590481Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-25T19:33:23.778598Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-07-25T19:33:23.778621Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-07-25T19:33:23.779801Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2022-07-25T19:33:23.790924Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
2022-07-25T19:33:23.790961Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.29' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2022-07-25 19:33:23+00:00 [Note] [Entrypoint]: Temporary server started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2022-07-25 19:33:24+00:00 [Note] [Entrypoint]: Stopping temporary server
2022-07-25T19:33:24.911894Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.29).
2022-07-25T19:33:26.423537Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29) MySQL Community Server - GPL.
2022-07-25 19:33:26+00:00 [Note] [Entrypoint]: Temporary server stopped
2022-07-25 19:33:26+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2022-07-25T19:33:27.122487Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-07-25T19:33:27.128121Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-25T19:33:27.217345Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-07-25T19:33:27.410605Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-07-25T19:33:27.410659Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-07-25T19:33:27.412287Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2022-07-25T19:33:27.431360Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-07-25T19:33:27.431373Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.29' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
And after second attempt container is up and running normally. So my question is - how to identify what causes to the SHUTDOWN command?
That's a normal consequence of the way the mysql image runs its first-time initialization scripts. Note the Initializing database files message and the Temporary server started...Temporary server stopped around the first Received SHUTDOWN message.
You can see this logic in the entrypoint script itself. That script runs (using shell functions defined previously in the script, trimmed down somewhat)
# there's no database, so it needs to be initialized
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_init_database_dir "$#"
mysql_note "Starting temporary server"
docker_temp_server_start "$#"
mysql_note "Temporary server started"
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*
mysql_note "Stopping temporary server"
docker_temp_server_stop
mysql_note "Temporary server stopped"
fi
The mysql_note lines are visible in the container output you quote.
More specifically, the temporary server is accessible over a Unix socket within the container filesystem, but it is not accessible over the network. This gives a point where the database hasn't been set up yet, but it's still possible to run local mysql commands, for example from the initdb scripts. Once this phase has been complete, then the database restarts with its normal options.
If you're probing to see if the database is ready yet, maybe using a mysql client in a shell loop or a TCP client like the wait-for script, this means that the database won't appear "ready" until all of the initdb scripts have run.

Custom MySQL docker image using existing sql file

I want to create a custom MySQL docker image in https://labs.play-with-docker.com/ using existing mysql file. MySQL file looks like below.
abc.sql
create schema my-schema1;
use my-schema1;
create table table1(
id bigint primary key,
name varchar(50)
);
insert into table1 values(7009009001,'Carry');
select * from table1;
create schema my-schema2;
use my-schema2;
create table table2(
id bigint primary key,
name varchar(50)
);
insert into table1 values(4009009001,'Marry');
select * from table2;
Dockerfile
FROM mysql
COPY ./abc.sql /docker-entrypoint-initdb.d/abc.sql
I am running below commands :
docker pull mysql:latest
docker build -f Dockerfile -t custom-mysql-img .
docker run --name=mysql-con --volume custom-mysql-volume:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d custom-mysql-img
docker exec -it mysql-con mysql -u root -p
Container gets started and asks for password. But on executing show databases; command it only displays default schemas. I need multiple schemas and tables in my .sql file, hence don't want to put schema name in Dockerfile.
Please suggest where I am wrong.
Below is the output of docker logs mysql-con :
$ docker logs mysql-con
2021-04-18 13:16:39+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-04-18 13:16:39+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-04-18 13:16:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-04-18 13:16:40+00:00 [Note] [Entrypoint]: Initializing database files
2021-04-18T13:16:40.236069Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.23) initializing of server in progress as process 42
2021-04-18T13:16:40.253242Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-04-18T13:16:40.923755Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-04-18T13:16:43.583388Z 6 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2021-04-18 13:16:47+00:00 [Note] [Entrypoint]: Database files initialized
2021-04-18 13:16:47+00:00 [Note] [Entrypoint]: Starting temporary server
2021-04-18T13:16:47.959622Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.23) starting as process 87
2021-04-18T13:16:48.100393Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-04-18T13:16:48.506573Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-04-18T13:16:48.753607Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
2021-04-18T13:16:49.015712Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-04-18T13:16:49.018919Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-04-18T13:16:49.023237Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2021-04-18T13:16:49.082436Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.23' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2021-04-18 13:16:49+00:00 [Note] [Entrypoint]: Temporary server started.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2021-04-18 13:16:55+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/abc.sql
/usr/local/bin/docker-entrypoint.sh: line 75: /docker-entrypoint-initdb.d/abc.sql: Permission denied
2021-04-18 13:17:43+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-04-18 13:17:43+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-04-18 13:17:43+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-04-18T13:17:44.067090Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.23) starting as process 1
2021-04-18T13:17:44.082414Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-04-18T13:17:45.999169Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-04-18T13:17:46.234843Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2021-04-18T13:17:46.322310Z 0 [System] [MY-010229] [Server] Starting XA crash recovery...
2021-04-18T13:17:46.378281Z 0 [System] [MY-010232] [Server] XA crash recovery finished.
2021-04-18T13:17:46.454642Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-04-18T13:17:46.455015Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-04-18T13:17:46.459673Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2021-04-18T13:17:46.491885Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.23' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.

How to connect to docker-compose mysql after container has initilized?

I have a project that I have been working on and now I am experimenting with docker-compose to build it.
Before running my own custom scripts to create tables and such I thought I would just give it a go and see if it builds and I can connect to it.
I found a suitable docker-compose for mysql:
version: "3.8"
services:
mysql:
image: mysql:latest
ports:
- 3307:3307
environment:
MYSQL_ROOT_PASSWORD: SomeRootPassword1!
MYSQL_USER: someuser
MYSQL_PASSWORD: Password1!
MYSQL_DATABASE: wedding
After running docker-compose-up in gitbash I see:
mysql_1 | 2020-08-26 20:00:14+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
mysql_1 | 2020-08-26 20:00:14+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql_1 | 2020-08-26 20:00:14+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
mysql_1 | 2020-08-26 20:00:14+00:00 [Note] [Entrypoint]: Initializing database files
mysql_1 | 2020-08-26T20:00:14.502438Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as process 43
mysql_1 | 2020-08-26T20:00:14.507639Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql_1 | 2020-08-26T20:00:15.519301Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql_1 | 2020-08-26T20:00:17.309017Z 6 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
mysql_1 | 2020-08-26 20:00:21+00:00 [Note] [Entrypoint]: Database files initialized
mysql_1 | 2020-08-26 20:00:21+00:00 [Note] [Entrypoint]: Starting temporary server
mysql_1 | 2020-08-26T20:00:22.149193Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 90
mysql_1 | 2020-08-26T20:00:22.170767Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql_1 | 2020-08-26T20:00:22.378726Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql_1 | 2020-08-26T20:00:22.457272Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
mysql_1 | 2020-08-26T20:00:22.549270Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql_1 | 2020-08-26T20:00:22.549394Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql_1 | 2020-08-26T20:00:22.553380Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql_1 | 2020-08-26T20:00:22.564741Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
mysql_1 | 2020-08-26 20:00:22+00:00 [Note] [Entrypoint]: Temporary server started.
mysql_1 | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
mysql_1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
mysql_1 | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
mysql_1 | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
mysql_1 | 2020-08-26 20:00:24+00:00 [Note] [Entrypoint]: Creating database wedding
mysql_1 | 2020-08-26 20:00:24+00:00 [Note] [Entrypoint]: Creating user someuser
mysql_1 | 2020-08-26 20:00:24+00:00 [Note] [Entrypoint]: Giving user someuser access to schema wedding
mysql_1 |
mysql_1 | 2020-08-26 20:00:24+00:00 [Note] [Entrypoint]: Stopping temporary server
mysql_1 | 2020-08-26T20:00:24.697408Z 14 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.21).
mysql_1 | 2020-08-26T20:00:27.792197Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.21) MySQL Community Server - GPL.
mysql_1 | 2020-08-26 20:00:28+00:00 [Note] [Entrypoint]: Temporary server stopped
mysql_1 |
mysql_1 | 2020-08-26 20:00:28+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
mysql_1 |
mysql_1 | 2020-08-26T20:00:28.931847Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1
mysql_1 | 2020-08-26T20:00:28.947655Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql_1 | 2020-08-26T20:00:29.162873Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql_1 | 2020-08-26T20:00:29.250374Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql_1 | 2020-08-26T20:00:29.322041Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql_1 | 2020-08-26T20:00:29.322181Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql_1 | 2020-08-26T20:00:29.328435Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql_1 | 2020-08-26T20:00:29.343021Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
The problem
Now that above is finished(Not sure if all is correct) I thought I would try and connect to it via mysql workbench but Im getting the following:
I also tried changing my binding address to :
What am I doing wrong?
In the compose file, under ports: you creating a forwarding rule from localhost:3307 to container:3307.
While you can choose any source port that is not in use on your host machine, at the other end you must hit the port on which the container is listening: in this case it would be 3306.
Your docker-compose.yml file should look like this:
version: "3.8"
services:
mysql:
image: mysql:latest
ports:
- 3307:3306
environment:
MYSQL_ROOT_PASSWORD: SomeRootPassword1!
MYSQL_USER: someuser
MYSQL_PASSWORD: Password1!
MYSQL_DATABASE: wedding
...then you should be able to connect at localhost:3307
You need to use docker internal network to bind address, instead of localhost (if you are not exposing the port), replacing 0.0.0.0 for host.docker.internal. This should do the trick.

I am getting wordpress mysql connection error using docker

I created two docker containers using the commands below.
docker pull wordpress
docker pull mysql
docker run --name wordpress_database -e MYSQL_ROOT_PASSWORD=password -d mysql
docker run --name wordpress_website --link wordpress_database:mysql -p 8080:80 -d wordpress
When I looked at the later logs, I encountered an error. Logs are below.
How do I prevent these errors?
docker logs wordpress_website
WordPress not found in /var/www/html - copying now...
Complete! WordPress has been successfully copied to /var/www/html
[15-Apr-2020 12:08:38 UTC] PHP Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Standard input code on line 22
[15-Apr-2020 12:08:38 UTC] PHP Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in Standard input code on line 22
MySQL Connection Error: (2054) The server requested authentication method unknown to the client
[15-Apr-2020 12:08:41 UTC] PHP Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in Standard input code on line 22
[15-Apr-2020 12:08:41 UTC] PHP Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in Standard input code on line 22
WARNING: unable to establish a database connection to 'mysql'
continuing anyways (which might have unexpected results)
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
[Wed Apr 15 12:09:06.057462 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.16 configured -- resuming normal operations
[Wed Apr 15 12:09:06.057505 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
docker logs wordpress_database
2020-04-15 12:07:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-15 12:07:20+00:00 [Note] [Entrypoint]: Initializing database files
2020-04-15T12:07:20.102858Z 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.
2020-04-15T12:07:20.102959Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 43
2020-04-15T12:07:23.537919Z 5 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-04-15 12:07:27+00:00 [Note] [Entrypoint]: Database files initialized
2020-04-15 12:07:27+00:00 [Note] [Entrypoint]: Starting temporary server
2020-04-15T12:07:27.774674Z 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.
2020-04-15T12:07:27.774765Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 93
2020-04-15T12:07:28.389657Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-04-15T12:07:28.397651Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-04-15T12:07:28.421413Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
2020-04-15 12:07:28+00:00 [Note] [Entrypoint]: Temporary server started.
2020-04-15T12:07:28.457791Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2020-04-15 12:07:30+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-04-15T12:07:30.812504Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.19).
2020-04-15T12:07:32.529079Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL.
2020-04-15 12:07:32+00:00 [Note] [Entrypoint]: Temporary server stopped
2020-04-15 12:07:32+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
2020-04-15T12:07:33.133835Z 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.
2020-04-15T12:07:33.133938Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 1
2020-04-15T12:07:33.647310Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-04-15T12:07:33.652627Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-04-15T12:07:33.673452Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2020-04-15T12:07:33.812073Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
localhost:8080
Error establishing a database connection
You need to publish ports to the host interface for MySQL container. Use this command to start the MySQL docker container:
docker run --name wordpress_database -e MYSQL_ROOT_PASSWORD=password -d -p 3306:3306 mysql
Read this for more details regarding publishing ports in a docker container.

Docker-compose up throws Errors running first time and works ok after second run

When I run docker-compose up for the first time it throws Errors and is not working,
after second run everything works fine.
It is looking like something is missing during first run and is available during second run.
I want this working after first run.
These are my config files:
docker-compose.yml:
version: '3'
services:
api:
build: .
ports:
- "10012:10012"
database:
image: mysql
container_name: database
environment:
MYSQL_PASSWORD: ***
MYSQL_ROOT_PASSWORD: ***
MYSQL_USER: user
MYSQL_DATABASE: currencydb
ports:
- "3306:3306"
depends_on:
- api
Dockerfile:
FROM openjdk:8
ADD target/currency-rest-0.0.1-SNAPSHOT.jar .
EXPOSE 10011
CMD java -jar currency-rest-0.0.1-SNAPSHOT.jar
application.properties:
server.port=10012
spring.jpa.ddl-auto=create
spring.datasource.url=jdbc:mysql://database:3306/currencydb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=***
spring.jpa.hibernate.ddl-auto=update
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
Console output after first run:
PS C:\Users\wuher\desktop\currency-rest> docker-compose up
docker-compose : Building api
At line:1 char:1
+ docker-compose up
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Building api:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Step 1/4 : FROM openjdk:8
---> f8146facf376
Step 2/4 : ADD target/currency-rest-0.0.1-SNAPSHOT.jar .
---> fd52b0529742
Step 3/4 : EXPOSE 10011
---> Running in dba375d741f8
Removing intermediate container dba375d741f8
---> 2dd51a3c0782
Step 4/4 : CMD java -jar currency-rest-0.0.1-SNAPSHOT.jar
---> Running in 7d204a8fc8d5
Removing intermediate container 7d204a8fc8d5
---> 1010d46a1bb8
Successfully built 1010d46a1bb8
Successfully tagged currency-rest_api:latest
Image for service api was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating currency-rest_api_1 ...
[1A[2KCreating currency-rest_api_1 ... [32mdone[0m[1B
Creating database ...
[1A[2KCreating database ... [32mdone[0m[1B
Attaching to currency-rest_api_1, database
[33mdatabase |[0m 2020-01-12 23:44:32+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
[33mdatabase |[0m 2020-01-12 23:44:32+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
[33mdatabase |[0m 2020-01-12 23:44:32+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
[33mdatabase |[0m 2020-01-12 23:44:32+00:00 [Note] [Entrypoint]: Initializing database files
[33mdatabase |[0m 2020-01-12T23:44:32.472398Z 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 rele
ase.
[33mdatabase |[0m 2020-01-12T23:44:32.472481Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.18) initializing of server in progress as process 45
[36mapi_1 |[0m
[36mapi_1 |[0m . ____ _ __ _ _
[36mapi_1 |[0m /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
[36mapi_1 |[0m ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
[36mapi_1 |[0m \\/ ___)| |_)| | | | | || (_| | ) ) ) )
[36mapi_1 |[0m ' |____| .__|_| |_|_| |_\__, | / / / /
[36mapi_1 |[0m =========|_|==============|___/=/_/_/_/
[36mapi_1 |[0m :: Spring Boot :: (v2.2.2.RELEASE)
[36mapi_1 |[0m
[36mapi_1 |[0m 2020-01-12 23:44:32.707 INFO 6 --- [ main] p.k.c.CurrencyRestApplication : Starting CurrencyRestApplication v0.0.1-SNAPSHOT on b5facd58e175 with PID 6 (/currency-rest-0.0.1-SNAPSHOT.jar started by root in /)
[36mapi_1 |[0m 2020-01-12 23:44:32.750 INFO 6 --- [ main] p.k.c.CurrencyRestApplication : No active profile set, falling back to default profiles: default
[36mapi_1 |[0m 2020-01-12 23:44:33.783 INFO 6 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
[36mapi_1 |[0m 2020-01-12 23:44:33.904 INFO 6 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 104ms. Found 3 JPA repository interfaces.
[36mapi_1 |[0m 2020-01-12 23:44:34.426 INFO 6 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotat
ion.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[36mapi_1 |[0m 2020-01-12 23:44:34.822 INFO 6 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 10012 (http)
[36mapi_1 |[0m 2020-01-12 23:44:34.841 INFO 6 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
[36mapi_1 |[0m 2020-01-12 23:44:34.841 INFO 6 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
[33mdatabase |[0m 2020-01-12T23:44:35.145873Z 5 [Warning] [MY-010453] [Server] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[36mapi_1 |[0m 2020-01-12 23:44:35.391 INFO 6 --- [ main] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were sc
anned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[36mapi_1 |[0m 2020-01-12 23:44:35.697 INFO 6 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
[36mapi_1 |[0m 2020-01-12 23:44:35.697 INFO 6 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2840 ms
[36mapi_1 |[0m 2020-01-12 23:44:36.207 INFO 6 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
[36mapi_1 |[0m 2020-01-12 23:44:36.293 INFO 6 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.9.Final}
[36mapi_1 |[0m 2020-01-12 23:44:36.499 INFO 6 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
[36mapi_1 |[0m 2020-01-12 23:44:36.665 INFO 6 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
[36mapi_1 |[0m 2020-01-12 23:44:36.770 ERROR 6 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
[36mapi_1 |[0m
[36mapi_1 |[0m com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
[36mapi_1 |[0m
[36mapi_1 |[0m The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
[36mapi_1 |[0m at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~]
/////
cut part of code
/////
[36mapi_1 |[0m Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
[36mapi_1 |[0m
[36mapi_1 |[0m The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
[36mapi_1 |[0m at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_232]
[36mapi_1 |[0m at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_232]
[36mapi_1 |[0m at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_232]
[36mapi_1 |[0m at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_232]
[36mapi_1 |[0m at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m ... 57 common frames omitted
[36mapi_1 |[0m Caused by: java.net.ConnectException: Connection refused (Connection refused)
[36mapi_1 |[0m at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_232]
[36mapi_1 |[0m at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_232]
[36mapi_1 |[0m at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_232]
[36mapi_1 |[0m at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_232]
[36mapi_1 |[0m at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_232]
[36mapi_1 |[0m at java.net.Socket.connect(Socket.java:607) ~[na:1.8.0_232]
[36mapi_1 |[0m at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.18.jar!/:8.0.18]
[36mapi_1 |[0m ... 60 common frames omitted
[36mapi_1 |[0m
[36mapi_1 |[0m 2020-01-12 23:44:36.771 WARN 6 --- [ main] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : Communications link failure
[36mapi_1 |[0m
[36mapi_1 |[0m The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
[36mapi_1 |[0m 2020-01-12 23:44:36.775 WARN 6 --- [ 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 org.hibernate.service.spi.ServiceExce
ption: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
[36mapi_1 |[0m 2020-01-12 23:44:36.779 INFO 6 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
[36mapi_1 |[0m 2020-01-12 23:44:36.798 INFO 6 --- [ main] ConditionEvaluationReportLoggingListener :
[36mapi_1 |[0m
[36mapi_1 |[0m Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[36mapi_1 |[0m 2020-01-12 23:44:36.801 ERROR 6 --- [ main] o.s.boot.SpringApplication : Application run failed
///////
cut part of info
///////
[36mcurrency-rest_api_1 exited with code 1
[0m[33mdatabase |[0m 2020-01-12 23:44:38+00:00 [Note] [Entrypoint]: Database files initialized
[33mdatabase |[0m 2020-01-12 23:44:38+00:00 [Note] [Entrypoint]: Starting temporary server
[33mdatabase |[0m 2020-01-12T23:44:38.668558Z 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 rele
ase.
[33mdatabase |[0m 2020-01-12T23:44:38.668651Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 94
[33mdatabase |[0m 2020-01-12T23:44:39.078017Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
[33mdatabase |[0m 2020-01-12T23:44:39.082365Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
[33mdatabase |[0m 2020-01-12T23:44:39.102708Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.18' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
[33mdatabase |[0m 2020-01-12 23:44:39+00:00 [Note] [Entrypoint]: Temporary server started.
[33mdatabase |[0m 2020-01-12T23:44:39.243716Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
[33mdatabase |[0m Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
[33mdatabase |[0m Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
[33mdatabase |[0m Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
[33mdatabase |[0m Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
[33mdatabase |[0m 2020-01-12 23:44:41+00:00 [Note] [Entrypoint]: Creating database currencydb
[33mdatabase |[0m 2020-01-12 23:44:41+00:00 [Note] [Entrypoint]: Creating user user
[33mdatabase |[0m 2020-01-12 23:44:41+00:00 [Note] [Entrypoint]: Giving user user access to schema currencydb
[33mdatabase |[0m
[33mdatabase |[0m 2020-01-12 23:44:41+00:00 [Note] [Entrypoint]: Stopping temporary server
[33mdatabase |[0m 2020-01-12T23:44:41.782901Z 14 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.18).
[33mdatabase |[0m 2020-01-12T23:44:43.508856Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.18) MySQL Community Server - GPL.
[33mdatabase |[0m 2020-01-12 23:44:43+00:00 [Note] [Entrypoint]: Temporary server stopped
[33mdatabase |[0m
[33mdatabase |[0m 2020-01-12 23:44:43+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
[33mdatabase |[0m
[33mdatabase |[0m 2020-01-12T23:44:44.029991Z 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 rele
ase.
[33mdatabase |[0m 2020-01-12T23:44:44.030080Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 1
[33mdatabase |[0m 2020-01-12T23:44:44.448592Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
[33mdatabase |[0m 2020-01-12T23:44:44.452896Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
[33mdatabase |[0m 2020-01-12T23:44:44.467507Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.18' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
[33mdatabase |[0m 2020-01-12T23:44:44.636049Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
What am I doing wrong?
As per your docker-compose you are expecting your App to run before Database.
But App has a dependency on MySQL and if it's not up SpringBoot will throw error.
Please change your depends_on configuration like this.
version: '3'
services:
api:
build: .
ports:
- "10012:10012"
depends_on:
- database
database:
image: mysql
container_name: database
environment:
MYSQL_PASSWORD: ***
MYSQL_ROOT_PASSWORD: ***
MYSQL_USER: user
MYSQL_DATABASE: currencydb
ports:
- "3306:3306"
Refer more in detail here. Search for depends_on