- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我第一次运行 docker-compose up 时,它会抛出错误并且无法工作,第二次运行后一切正常。看起来第一次运行期间缺少某些内容,但在第二次运行期间可用。我希望它在第一次运行后起作用。
这些是我的配置文件:
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
应用程序属性:
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
首次运行后控制台输出:
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
我做错了什么?
最佳答案
根据您的docker-compose
,您希望您的应用程序
在数据库
之前运行。
但是应用程序依赖于MySQL
,如果它没有启动SpringBoot
将抛出错误。
请像这样更改您的depends_on
配置。
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"
更详细请参阅here 。搜索depends_on
关于mysql - Docker-compose up 第一次运行时抛出错误,第二次运行后工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59709324/
来自 java docs 公共(public) FileWriter(String fileName) 抛出 IOException 抛出: IOException - 如果指定的文件存在但它是目录而
我使用以下代码将我的 .net 客户端(基于 CQL)连接到 3 节点 Cassandra 集群。我以 30 条记录/秒的速度(从 RabbitMQ)获取数据,并且它们顺利地存储在 cassandra
如果在读取文件时缺少字段,我应该捕获 NoSuchElementException。如果缺少一个字段,我只需要跳到文件的下一行。我的问题是,我在哪里实现我的 try/catch 代码来做到这一点?这是
我正在尝试使用 ASP.NET MVC 实现 OpeinID 登录。我正在尝试按照 http://blog.nerdbank.net/2008/04/add-openid-login-support-
学习使用 Java 进行 xml 解析,并且正在编写一个测试程序来尝试各种东西。所有测试 System.out.println() 都是我在控制台中所期望的,除了 childElement 返回 [n
我正在尝试使用 SwingUtilities 创建 JFrame Thread tt = new Thread(new Runnable() { public void run
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我写了这段代码: MethodInfo method2 = typeof(IntPtr).GetMethod( "op_Explicit", Bind
我开始学习 Java,并且正在根据书本做一些练习。在执行此操作时,我遇到了以下错误:线程“main”java.util.InputMismatchException 中出现异常。我正在编写一个简单的程
我有一个文本文件,其中前两行是整数 m 和 n,然后有 m 行,每行都有 n 管道分隔值。我编写了一个程序,读取文件并使用文件中的值创建 m*n 数组,它工作了无数次,然后突然,使用相同的代码,使用相
所以我尝试使用在另一个类中生成的 bean 以在主应用程序中使用 package com.simon.spring.basics.properties; import org.spri
我还没有完成这个应用程序,但我希望在我的手机上看到它的样子。但是,它会强制关闭并引发 InstantiationException。 logcat 异常: 09-19 20:13:47.987: D/
我想从 UIViewController 加载一个基于 SwiftUI 的 View ,该 View 读取包本地的 json。仅 swiftUI 项目中的代码和绑定(bind)工作正常,当我利用 UI
'java.net.SocketTimeoutException:连接超时' 循环一段时间后我收到此错误。为什么我会收到 SocketTimeoutException?我该如何修复这个错误? @Ove
当有 null 值时抛出 ArgumentNullException() 是个好主意吗? This thread 没有提到在 null 上抛出的最明显的异常。 谢谢 最佳答案 ArgumentNull
我得到这个异常: NullReferenceException Object reference not set to an instance of an object at Namespace
所以其中一个方法的描述如下: public BasicLinkedList addToFront(T data) This operation is invalid for a sorted list
我正在使用 Intellij Idea,当我去生成 JavaDocs(通过工具 -> 生成 JavaDoc)时,我抛出了一个 IllegealArgumentException,没有关于发生了什么问题
我正在学习 C++ 中的互斥锁,但以下代码(摘自 N. Josuttis 的“C++ 标准库”)有问题。 我不明白为什么它会阻塞/抛出除非我在主线程中添加this_thread::sleep_for(
我正在试验 JavaFX 标签和组,通过鼠标拖动将它们移动到屏幕上。新节点从一些线程添加到动画组。但是,有时我会突然看到以下异常 - 我假设,当某些节点重叠时。但是不知道是什么问题……因为不涉及我的代
我是一名优秀的程序员,十分优秀!