mongodb - Docker Compose 启动 Spring-Boot 应用程序失败
问题描述
我有一个使用 Spring Boot 5 编写的小型推文微服务,它使用 MongoDB 作为持久层。我正在尝试编写一个 docker-compose 文件来使用新的数据库实例启动服务。当我单独启动数据库brew services start mongodb-community@4.4
然后启动应用程序时,应用程序在 localhost: 上启动。下面是我的docker-compose.yml
文件:
version: '3'
services:
mongo:
image: mongo:4.2.2
container_name: webflux_demo
network_mode: host
volumes:
- $HOME/mongo:/data/db
hostname: localhost
ports:
- "27017:27017"
healthcheck:
test: "exit 0"
webflux-demo:
build: webflux-demo/
image: webflux-demo:latest
depends_on:
- mongo
network_mode: "host"
hostname: localhost
restart: always
ports:
- "8082:8082"
healthcheck:
test: "exit 0"
当我运行时,docker-compose up
我得到控制台输出 -
Starting webflux_demo ... done
Starting webflux-demo-docker_webflux-demo_1 ... done
Attaching to webflux_demo, webflux-demo-docker_webflux-demo_1
webflux_demo | 2020-12-22T19:20:10.344+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=localhost
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] db version v4.2.2
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] allocator: tcmalloc
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] modules: none
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] build environment:
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] distmod: ubuntu1804
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] distarch: x86_64
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] target_arch: x86_64
webflux_demo | 2020-12-22T19:20:10.348+0000 I CONTROL [initandlisten] options: { net: { bindIp: "*" } }
webflux_demo | 2020-12-22T19:20:10.353+0000 I STORAGE [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
webflux_demo | 2020-12-22T19:20:10.357+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=483M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
webflux-demo_1 |
webflux-demo_1 | . ____ _ __ _ _
webflux-demo_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
webflux-demo_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
webflux-demo_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
webflux-demo_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
webflux-demo_1 | =========|_|==============|___/=/_/_/_/
webflux-demo_1 | :: Spring Boot :: (v2.3.4.RELEASE)
webflux-demo_1 |
webflux-demo_1 | 2020-12-22 19:20:11.433 INFO 1 --- [ main] c.e.webfluxdemo.WebfluxDemoApplication : Starting WebfluxDemoApplication v0.0.1-SNAPSHOT on localhost with PID 1 (/usr/src/webflux-demo-0.0.1-SNAPSHOT.jar started by root in /usr/src)
webflux-demo_1 | 2020-12-22 19:20:11.438 INFO 1 --- [ main] c.e.webfluxdemo.WebfluxDemoApplication : No active profile set, falling back to default profiles: default
webflux-demo_1 | 2020-12-22 19:20:12.024 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive MongoDB repositories in DEFAULT mode.
webflux-demo_1 | 2020-12-22 19:20:12.316 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 288ms. Found 1 Reactive MongoDB repository interfaces.
webflux-demo_1 | 2020-12-22 19:20:12.965 INFO 1 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[host.docker.internal:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
webflux-demo_1 | 2020-12-22 19:20:13.236 INFO 1 --- [.internal:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server host.docker.internal:27017
webflux-demo_1 |
webflux-demo_1 | com.mongodb.MongoSocketOpenException: Exception opening socket
webflux-demo_1 | at com.mongodb.connection.netty.NettyStream$OpenChannelFutureListener.operationComplete(NettyStream.java:416) ~[mongodb-driver-core-4.0.5.jar!/:na]
webflux-demo_1 | at com.mongodb.connection.netty.NettyStream$OpenChannelFutureListener.operationComplete(NettyStream.java:384) ~[mongodb-driver-core-4.0.5.jar!/:na]
webflux-demo_1 | at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:577) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:570) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:549) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:490) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:615) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:608) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:321) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:337) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:702) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_275]
webflux-demo_1 | Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: host.docker.internal/192.168.65.2:27017
webflux-demo_1 | Caused by: java.net.ConnectException: Connection refused
webflux-demo_1 | at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_275]
webflux-demo_1 | at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716) ~[na:1.8.0_275]
webflux-demo_1 | at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:702) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.52.Final.jar!/:4.1.52.Final]
webflux-demo_1 | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_275]
webflux-demo_1 |
webflux-demo_1 | 2020-12-22 19:20:13.991 INFO 1 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080
webflux-demo_1 | 2020-12-22 19:20:14.004 INFO 1 --- [ main] c.e.webfluxdemo.WebfluxDemoApplication : Started WebfluxDemoApplication in 3.139 seconds (JVM running for 3.621)
webflux_demo | 2020-12-22T19:20:16.783+0000 I STORAGE [initandlisten] WiredTiger message [1608664816:783556][1:0x7f4f01be5b00], txn-recover: Recovering log 9 through 10
webflux_demo | 2020-12-22T19:20:17.015+0000 I STORAGE [initandlisten] WiredTiger message [1608664817:15330][1:0x7f4f01be5b00], txn-recover: Recovering log 10 through 10
webflux_demo | 2020-12-22T19:20:17.544+0000 I STORAGE [initandlisten] WiredTiger message [1608664817:544424][1:0x7f4f01be5b00], txn-recover: Main recovery loop: starting at 9/5760 to 10/256
webflux_demo | 2020-12-22T19:20:17.898+0000 I STORAGE [initandlisten] WiredTiger message [1608664817:898842][1:0x7f4f01be5b00], txn-recover: Recovering log 9 through 10
webflux_demo | 2020-12-22T19:20:18.170+0000 I STORAGE [initandlisten] WiredTiger message [1608664818:170905][1:0x7f4f01be5b00], txn-recover: Recovering log 10 through 10
webflux_demo | 2020-12-22T19:20:18.223+0000 I STORAGE [initandlisten] WiredTiger message [1608664818:223844][1:0x7f4f01be5b00], txn-recover: Set global recovery timestamp: (0,0)
webflux_demo | 2020-12-22T19:20:18.252+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
webflux_demo | 2020-12-22T19:20:18.265+0000 I STORAGE [initandlisten] Timestamp monitor starting
webflux_demo | 2020-12-22T19:20:18.267+0000 I CONTROL [initandlisten]
webflux_demo | 2020-12-22T19:20:18.268+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
webflux_demo | 2020-12-22T19:20:18.268+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
webflux_demo | 2020-12-22T19:20:18.268+0000 I CONTROL [initandlisten]
webflux_demo | 2020-12-22T19:20:18.279+0000 I SHARDING [initandlisten] Marking collection local.system.replset as collection version: <unsharded>
webflux_demo | 2020-12-22T19:20:18.294+0000 I STORAGE [initandlisten] Flow Control is enabled on this deployment.
webflux_demo | 2020-12-22T19:20:18.295+0000 I SHARDING [initandlisten] Marking collection admin.system.roles as collection version: <unsharded>
webflux_demo | 2020-12-22T19:20:18.295+0000 I SHARDING [initandlisten] Marking collection admin.system.version as collection version: <unsharded>
webflux_demo | 2020-12-22T19:20:18.304+0000 I SHARDING [initandlisten] Marking collection local.startup_log as collection version: <unsharded>
webflux_demo | 2020-12-22T19:20:18.305+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
webflux_demo | 2020-12-22T19:20:18.309+0000 I SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version: <unsharded>
webflux_demo | 2020-12-22T19:20:18.310+0000 I NETWORK [initandlisten] Listening on /tmp/mongodb-27017.sock
webflux_demo | 2020-12-22T19:20:18.311+0000 I NETWORK [initandlisten] Listening on 0.0.0.0
webflux_demo | 2020-12-22T19:20:18.312+0000 I NETWORK [initandlisten] waiting for connections on port 27017
webflux_demo | 2020-12-22T19:20:18.313+0000 I SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version: <unsharded>
webflux_demo | 2020-12-22T19:20:19.008+0000 I SHARDING [ftdc] Marking collection local.oplog.rs as collection version: <unsharded>
当我检查docker ps -a
控制台时,我看到端口为空 -
我在 docker-compose 文件中做错了什么?
解决方案
推荐阅读
- c++ - 重定向到文件的 c++ cout 比使用 ofstream 慢
- vue.js - 将 vue-videobg 与 Nuxt 一起使用
- php - htaccess 工作正常,但少数链接不起作用
- java - 在硒中获取文本()不返回文本
- javascript - javascript onclick 仅在第二次点击后有效
- apache-kafka - python同时使用KafkaConsumer和Producer
- javascript - 有谁知道为什么 res.download 每次都给我的下载文件一个随机名称?
- python - 熊猫根据其他细胞的连续填充细胞
- xml - 无法将 ixmlnode 转换为从 ixmlnode 继承的其他接口
- sql-server - 有没有办法根据列值批量插入到 SQL Server 表中