我正在尝试基于this repository创建一个卑鄙的应用程序,我已经将Express容器中的api和Angular中的前端分开了。
现在,我正在尝试从正式的mongo映像创建数据库,它的工作原理很吸引人。但是,当我尝试添加卷以保留数据时,出现以下错误:
express_1 |无法连接到数据库MongoNetworkError:失败 首先连接到[MongoNetworkError:连接到服务器[mongo:27017] 连接ECONNREFUSED 172.31.0.2:27017]。
我做错什么了吗?
这是我的docker-compose文件:
version: '3'
networks:
my_network:
driver: bridge
services:
angular:
build: angular-app
links:
- express
ports:
- "5555:5555"
networks:
- my_network
express:
build: express-app
links:
- mongo
ports:
- "3000:3000"
networks:
- my_network
mongo:
image: mongo
environment:
- MONGO_DATA_DIR=/data/db
volumes:
- "./data/db:/data/db"
ports:
- "27017:27017"
networks:
my_network:
aliases:
- mongo
这是我的猫鼬连接器:
mongodb://mongo:27017/ng7crud
提前谢谢!
编辑:如@michalhosna所述,docker-compose logs mongo
的结果:
Attaching to projet_mongo_1
mongo_1 | 2019-01-31T23:11:22.336+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
mongo_1 | 2019-01-31T23:11:22.346+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=2523b067e6fc
mongo_1 | 2019-01-31T23:11:22.346+0000 I CONTROL [initandlisten] db version v4.0.5
mongo_1 | 2019-01-31T23:11:22.346+0000 I CONTROL [initandlisten] git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
mongo_1 | 2019-01-31T23:11:22.347+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
mongo_1 | 2019-01-31T23:11:22.347+0000 I CONTROL [initandlisten] allocator: tcmalloc
mongo_1 | 2019-01-31T23:11:22.347+0000 I CONTROL [initandlisten] modules: none
mongo_1 | 2019-01-31T23:11:22.347+0000 I CONTROL [initandlisten] build environment:
mongo_1 | 2019-01-31T23:11:22.347+0000 I CONTROL [initandlisten] distmod: ubuntu1604
mongo_1 | 2019-01-31T23:11:22.347+0000 I CONTROL [initandlisten] distarch: x86_64
mongo_1 | 2019-01-31T23:11:22.347+0000 I CONTROL [initandlisten] target_arch: x86_64
mongo_1 | 2019-01-31T23:11:22.347+0000 I CONTROL [initandlisten] options: { net: { bindIpAll: true } }
mongo_1 | 2019-01-31T23:11:22.377+0000 I STORAGE [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
mongo_1 | 2019-01-31T23:11:22.385+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=487M,session_max=20000,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),statistics_log=(wait=0),verbose=(recovery_progress),
mongo_1 | 2019-01-31T23:11:33.474+0000 I STORAGE [initandlisten] WiredTiger message [1548976293:474858][1:0x7f935195fa40], txn-recover: Main recovery loop: starting at 1/24064 to 2/256
mongo_1 | 2019-01-31T23:11:34.376+0000 I STORAGE [initandlisten] WiredTiger message [1548976294:376222][1:0x7f935195fa40], txn-recover: Recovering log 1 through 2
mongo_1 | 2019-01-31T23:11:35.031+0000 I STORAGE [initandlisten] WiredTiger message [1548976295:31496][1:0x7f935195fa40], txn-recover: Recovering log 2 through 2
mongo_1 | 2019-01-31T23:11:35.086+0000 I STORAGE [initandlisten] WiredTiger message [1548976295:86288][1:0x7f935195fa40], txn-recover: Set global recovery timestamp: 0
mongo_1 | 2019-01-31T23:11:35.141+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
mongo_1 | 2019-01-31T23:11:35.231+0000 I CONTROL [initandlisten]
mongo_1 | 2019-01-31T23:11:35.231+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
mongo_1 | 2019-01-31T23:11:35.233+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
mongo_1 | 2019-01-31T23:11:35.236+0000 I CONTROL [initandlisten]
mongo_1 | 2019-01-31T23:11:35.306+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
mongo_1 | 2019-01-31T23:11:35.316+0000 I NETWORK [initandlisten] waiting for connections on port 27017
编辑2:
看来issue带有mongodb,windows和macOS(因为它们使用NTFS)。
现在,我添加了:
volume:
mongodata:
在docker-compose.yml中的网络和服务之间,并且有效