我使用docker撰写启动一个mysql da和一个springstart应用程序。
这是我的docker-compose.yml
version: '3'
services:
sql:
image: mysql
environment:
MYSQL_DATABASE: people
MYSQL_USER: root
MYSQL_PASSWORD: my-secret-pw
MYSQL_ROOT_PASSWORD: my-secret-pw
ports:
- "3307:3306"
appointment-service:
depends_on:
- sql # This service depends on mysql. Start that first.
environment: # Pass environment variables to the service
- DATABASE_HOST=sql
- DATABASE_USER=root
- DATABASE_PASSWORD=my-secret-pw
- DATABASE_NAME=people
- DATABASE_PORT=3306
links:
- "sql:localhost"
build: .
ports:
- "8081:8081"
这是我的application.properties
server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/people?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=my-secret-pw
url.organizations = https://hr.apografi.gov.gr/api/public/organizations
url.db = jdbc:mysql://localhost:3306/people?serverTimezone=UTC
url.username = root
url.password = my-secret-pw
在这里,我创建了jdbi:
private Jdbi jdbi = Jdbi.create("jdbc:mysql://localhost:3306/people?useSSL=false&allowPublicKeyRetrieval=true", "root", "my-secret-pw");
不管我怎么做,我都无法让集装箱在码头内相互交谈。如果我单独启动sql,我可以在主机中看到连接(在datagrip中)。如果我从容器中运行java程序,它会看到主机中的数据库。即使我运行docker compose文件,也会创建两个容器,并且我可以从主机访问它们。我知道在DockerVM中存在名为sql的数据库/I已尝试使用sql名称和localhost名称(从links属性)。但无论我尝试了什么,我都无法从Docker中的java程序访问它。
这是stackTrace
docker-compose up --build
Building appointment-service
Step 1/4 : FROM openjdk:8-jdk-alpine
---> a3562aa0b991
Step 2/4 : ARG JAR_FILE=target/*.jar
---> Using cache
---> 603b2c59103f
Step 3/4 : COPY ${JAR_FILE} app.jar
---> Using cache
---> 4783d891166c
Step 4/4 : ENTRYPOINT ["java","-jar","/app.jar"]
---> Using cache
---> 24deebb3147a
Successfully built 24deebb3147a
Successfully tagged appointments-service_appointment-service:latest
Starting appointments-service_sql_1 ... done
Starting appointments-service_appointment-service_1 ... done
Attaching to appointments-service_sql_1, appointments-service_appointment-service_1
sql_1 | 2020-09-11 16:47:27+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
sql_1 | 2020-09-11 16:47:27+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
sql_1 | 2020-09-11 16:47:27+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
sql_1 | 2020-09-11T16:47:28.258555Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1
sql_1 | 2020-09-11T16:47:28.275621Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
sql_1 | 2020-09-11T16:47:28.641173Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
sql_1 | 2020-09-11T16:47:28.823110Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
sql_1 | 2020-09-11T16:47:28.988711Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
sql_1 | 2020-09-11T16:47:28.989000Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
sql_1 | 2020-09-11T16:47:28.999907Z 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.
sql_1 | 2020-09-11T16:47:29.056993Z 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.
appointment-service_1 |
appointment-service_1 | . ____ _ __ _ _
appointment-service_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
appointment-service_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
appointment-service_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
appointment-service_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
appointment-service_1 | =========|_|==============|___/=/_/_/_/
appointment-service_1 | :: Spring Boot :: (v2.3.2.RELEASE)
appointment-service_1 |
appointment-service_1 | 2020-09-11 16:47:30.628 INFO 1 --- [ main] c.a.service.ServiceApplication : Starting ServiceApplication v0.0.1-SNAPSHOT on 5bbe74d3ddb0 with PID 1 (/app.jar started by root in /)
appointment-service_1 | 2020-09-11 16:47:30.635 INFO 1 --- [ main] c.a.service.ServiceApplication : No active profile set, falling back to default profiles: default
appointment-service_1 | 2020-09-11 16:47:32.822 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
appointment-service_1 | 2020-09-11 16:47:32.876 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 33ms. Found 0 JPA repository interfaces.
appointment-service_1 | 2020-09-11 16:47:34.254 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
appointment-service_1 | 2020-09-11 16:47:34.300 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
appointment-service_1 | 2020-09-11 16:47:34.302 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37]
appointment-service_1 | 2020-09-11 16:47:34.472 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
appointment-service_1 | 2020-09-11 16:47:34.473 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3697 ms
appointment-service_1 | 2020-09-11 16:47:35.055 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
appointment-service_1 | 2020-09-11 16:47:35.100 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
appointment-service_1 | 2020-09-11 16:47:36.338 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
appointment-service_1 |
appointment-service_1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
appointment-service_1 |
appointment-service_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
appointment-service_1 | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.5.jar!/:na]
appointment-service_1 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358) ~[HikariCP-3.4.5.jar!/:na]
appointment-service_1 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-3.4.5.jar!/:na]
appointment-service_1 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477) [HikariCP-3.4.5.jar!/:na]
appointment-service_1 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560) [HikariCP-3.4.5.jar!/:na]
appointment-service_1 | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-3.4.5.jar!/:na]
appointment-service_1 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) [HikariCP-3.4.5.jar!/:na]
appointment-service_1 | at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158) [spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116) [spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79) [spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:324) [spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.boot.jdbc.EmbeddedDatabaseConnection.isEmbedded(EmbeddedDatabaseConnection.java:120) [spring-boot-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateDefaultDdlAutoProvider.getDefaultDdlAuto(HibernateDefaultDdlAutoProvider.java:42) [spring-boot-autoconfigure-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.lambda$getVendorProperties$1(HibernateJpaConfiguration.java:130) [spring-boot-autoconfigure-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings.getDdlAuto(HibernateSettings.java:41) ~[spring-boot-autoconfigure-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineDdlAuto(HibernateProperties.java:136) ~[spring-boot-autoconfigure-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.getAdditionalProperties(HibernateProperties.java:102) ~[spring-boot-autoconfigure-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineHibernateProperties(HibernateProperties.java:94) ~[spring-boot-autoconfigure-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.getVendorProperties(HibernateJpaConfiguration.java:132) [spring-boot-autoconfigure-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(JpaBaseConfiguration.java:133) ~[spring-boot-autoconfigure-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
appointment-service_1 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
appointment-service_1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
appointment-service_1 | at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
appointment-service_1 | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:635) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
appointment-service_1 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.2.RELEASE.jar!/:2.3.2.RELEASE]
appointment-service_1 | at com.appointments.service.ServiceApplication.main(ServiceApplication.java:10) ~[classes!/:0.0.1-SNAPSHOT]
appointment-service_1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
appointment-service_1 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
appointment-service_1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
appointment-service_1 | at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
appointment-service_1 | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[app.jar:0.0.1-SNAPSHOT]
appointment-service_1 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:109) ~[app.jar:0.0.1-SNAPSHOT]
appointment-service_1 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[app.jar:0.0.1-SNAPSHOT]
appointment-service_1 | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[app.jar:0.0.1-SNAPSHOT]
appointment-service_1 | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
appointment-service_1 |
appointment-service_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
appointment-service_1 | at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_212]
appointment-service_1 | at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_212]
appointment-service_1 | at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_212]
appointment-service_1 | at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_212]
appointment-service_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | ... 57 common frames omitted
appointment-service_1 | Caused by: java.net.ConnectException: Connection refused (Connection refused)
appointment-service_1 | at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_212]
appointment-service_1 | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_212]
appointment-service_1 | at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_212]
appointment-service_1 | at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_212]
appointment-service_1 | at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_212]
appointment-service_1 | at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_212]
appointment-service_1 | at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
appointment-service_1 | ... 60 common frames omitted
appointment-service_1
|
localhost
始终指向环回接口(要么127.0.0.1
要么::1
)。您不能,也不应该试图覆盖此。
使用docker compose时,您可以使用服务名称作为主机名,因此数据库的正确JDBC URL为:
jdbc:mysql://sql:3306/people?useSSL=false&allowPublicKeyRetrieval=true
链接:
在这种情况下已被弃用且无用-只需删除该行。localhost
在java容器内部使用将指向容器本身。您必须使用为sql容器提供的服务名称(在您的情况下为sql
)。服务名称将解析为SQL容器的IP。 depends_on:
将使java容器等待SQL容器启动,但这并不能保证SQL已经启动并运行,准备接受连接。有几种方法可以解决这个问题(等待,重启:失败,这篇文章等等) MYSQL_USER: root
也不需要指定MYSQL_PASSWORD: my-Secret-pw
。(version: '3'
services:
sql:
image: mysql
environment:
MYSQL_DATABASE: people
MYSQL_ROOT_PASSWORD: my-secret-pw
ports:
- "3307:3306"
appointment-service:
depends_on:
- sql # This service depends on mysql. Start that first.
restart: on-failure
environment: # Pass environment variables to the service
- DATABASE_HOST=sql
- DATABASE_USER=root
- DATABASE_PASSWORD=my-secret-pw
- DATABASE_NAME=people
- DATABASE_PORT=3306
build: .
ports:
- "8081:8081"
server.port=8081
spring.datasource.url=jdbc:mysql://sql:3306/people?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=my-secret-pw
url.organizations = https://hr.apografi.gov.gr/api/public/organizations
url.db = jdbc:mysql://sql:3306/people?serverTimezone=UTC
url.username = root
url.password = my-secret-pw
private Jdbi jdbi = Jdbi.create("jdbc:mysql://sql:3306/people?useSSL=false&allowPublicKeyRetrieval=true", "root", "my-secret-pw");
问题内容: 我正在尝试设置一个docker- compose文件,该文件旨在用Supervisor替换运行多个进程(RQ worker,RQ仪表板和Flask应用程序)的单个Docker容器解决方案。 主机系统是Debian 8 Linux,我的样子如下(我删除了所有其他条目以减少错误源): “ rq-worker1”是Python RQ工作者,尝试通过本地主机和端口6379连接到Redis,但无
我正在运行2个spring boot应用程序:一个客户端和rest-api。客户机与rest-api通信,rest-API与mongodb数据库通信。所有3层都在docker容器中运行。 我启动容器,通常指定docker文件中公开的端口,并将它们映射到主机上的端口,例如:-p 7070:7070,其中7070是docker文件中公开的端口。 当我通过< code > Java-jar[applic
试图在localhost中建立从app容器到mysql容器的连接,出现连接拒绝异常 我们正在采取一种docker的方法来调用rest api服务来采用微服务的方法。我们正在建立应用程序容器和mysql容器之间的连接,同时我们编写了一个docker-compose文件,创建了mysql容器和应用程序容器,为这两个容器公开了端口。下面是运行docker-compose文件docker-compose
我试图为Nginx+PHP(Laravel)+MySQL构建docker组合容器,但我不断收到连接拒绝错误 Docker-compose.yml 在中,我有一个全新的Laravel应用程序,它具有基本的SQL设置 所有容器都运行时没有错误,我可以使用以下方法连接到MySQL容器 但当我试图从浏览器访问或将ssh直接导入php容器时,我总是得到错误2002。 我有nginx和mysql运行在服务器上
我试图用PHP、MariaDB和一个教程创建一个PHP开发环境,该教程建议使用Adminer进行数据库管理。因此,我生成了我的文件如下: 但是,当我为MariaDB设置卷时,在管理员登录页面中出现了一个错误。当我没有设置它们时,它似乎工作得很好。
主要内容:网络端口映射,Docker 容器互联,配置 DNS前面我们实现了通过网络端口来访问运行在 docker 容器内的服务。 容器中可以运行一些网络应用,要让外部也可以访问这些应用,可以通过 -P 或 -p 参数来指定端口映射。 下面我们来实现通过端口连接到一个 docker 容器。 网络端口映射 我们创建了一个 python 应用的容器。 另外,我们可以指定容器绑定的网络地址,比如绑定 127.0.0.1。 我们使用 -P 绑定端口号,使用 dock