gpt4 book ai didi

docker - 如何链接 docker compose 文件 (docker-compose.yml) 中的容器?

转载 作者:行者123 更新时间:2023-12-02 19:36:47 25 4
gpt4 key购买 nike

我无法使用 docker compose 链接 MySQL 和运行容器。请参阅下面的 yml 文件:

zookeeper:
image: zookeeper:3.4
ports:
- 2181:2181
kafka:
image: ches/kafka:latest
ports:
- 9092:9092
links:
- zookeeper
myDpm:
image: dpm-image:latest
ports:
- 9000:9000
links:
- kafka
- zookeeper
mySql:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: root
myMc3:
image: mc3-v3:3.0
ports:
- 9001:9000
links:
- mySql:3306
environment:
runMode: dev
myElastic:
image: elasticsearch:2.4.0
ports:
- 9200:9200

我想将 mysql 与我的 play scala 项目链接起来。我收到一个错误:

[error] - [play.core.server.netty.PlayDefaultUpstreamHandler] - Cannot invoke the action java.sql.SQLTimeoutException: Timeout after 10001ms of waiting for a connection. at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:227) ~[com.zaxxer.HikariCP-java6-2.3.7.jar:na] at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:182) ~[com.zaxxer.HikariCP-java6-2.3.7.jar:na] at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:93) ~[com.zaxxer.HikariCP-java6-2.3.7.jar:na] at slick.jdbc.hikaricp.HikariCPJdbcDataSource.createConnection(HikariCPJdbcDataSource.scala:12) ~[com.typesafe.slick.slick-hikaricp_2.11-3.1.1.jar:na] at slick.jdbc.JdbcBackend$BaseSession.conn$lzycompute(JdbcBackend.scala:415) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.JdbcBackend$BaseSession.conn(JdbcBackend.scala:414) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.JdbcBackend$SessionDef$class.prepareStatement(JdbcBackend.scala:297) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.JdbcBackend$BaseSession.prepareStatement(JdbcBackend.scala:407) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.StatementInvoker.results(StatementInvoker.scala:33) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.StatementInvoker.iteratorTo(StatementInvoker.scala:22) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.Invoker$class.foreach(Invoker.scala:48) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.StatementInvoker.foreach(StatementInvoker.scala:16) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.Invoker$class.firstOption(Invoker.scala:24) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.StatementInvoker.firstOption(StatementInvoker.scala:16) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.StreamingInvokerAction$HeadOptionAction.run(StreamingInvokerAction.scala:57) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.jdbc.StreamingInvokerAction$HeadOptionAction.run(StreamingInvokerAction.scala:56) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.backend.DatabaseComponent$DatabaseDef$$anon$2.liftedTree1$1(DatabaseComponent.scala:237) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at slick.backend.DatabaseComponent$DatabaseDef$$anon$2.run(DatabaseComponent.scala:237) ~[com.typesafe.slick.slick_2.11-3.1.1.jar:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_111] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_111] at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_111] Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

最佳答案

如前所述here docker 链接在某种程度上被网络取代了。

Before the Docker network feature, you could use the Docker link feature to allow containers to discover each other. With the introduction of Docker networks, containers can be discovered by its name automatically.

默认情况下,组合文件中的所有容器都加入默认网络(如果没有定义其他网络),您应该能够通过使用服务名称和正确的端口从另一个服务访问一个服务,例如:mySql:3306

更多信息可以在 network docs from docker 中找到.

关于docker - 如何链接 docker compose 文件 (docker-compose.yml) 中的容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44152503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com