gpt4 book ai didi

mongodb - 从 docker-compose 导入 mongodb 数据

转载 作者:行者123 更新时间:2023-12-02 11:10:02 27 4
gpt4 key购买 nike

我想使用 docker-compose 将数据导入我的 mongodb 数据库,但我没有找到解决方案。这是我在某个地方得到的一个想法,但行不通。如果有人看到更好的解决方案或只是修复此解决方案,我会接受:)。谢谢

./docker-compose.yml

db:
image: mongo
ports:
- 27018:27017

dbseed:
build: ./dbseed
links:
- db

app:
build: .
links:
- db:db
ports:
-8080:8080
-8181:8181

dbseed/new_climat_final.json

[
{
"name": "Joe Smith",
"email": "jsmith@gmail.com",
"age": 40,
"admin": false
},
{
"name": "Jen Ford",
"email": "jford@gmail.com",
"age": 45,
"admin": true
}
]

dbseed/Dockerfile

FROM mongo

COPY new_climat_final.json /new_climat_final.json

CMD mongoimport --host db --db hpApiDev --collection coll --type json --file /new_climat_final.json --jsonArray

没有错误,但我的 mongodb 数据库中没有数据:/

Cf:docker-compose 日志

Attaching to dockernode_db_1, dockernode_dbseed_1
db_1 | 2015-12-22T00:57:46.629+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=d48c97fd7ca5
dbseed_1 | 2015-12-21T17:42:46.609+0000 Failed: open /new_climat_final.json: no such file or directory
db_1 | 2015-12-22T00:57:46.629+0000 I CONTROL [initandlisten] db version v3.2.0
dbseed_1 | 2015-12-21T17:42:46.609+0000 imported 0 documents
db_1 | 2015-12-22T00:57:46.629+0000 I CONTROL [initandlisten] git version: 45d947729a0315accb6d4f15a6b06be6d9c19fe7
db_1 | 2015-12-22T00:57:46.629+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
db_1 | 2015-12-22T00:57:46.629+0000 I CONTROL [initandlisten] allocator: tcmalloc
db_1 | 2015-12-22T00:57:46.629+0000 I CONTROL [initandlisten] modules: none
db_1 | 2015-12-22T00:57:46.629+0000 I CONTROL [initandlisten] build environment:
db_1 | 2015-12-22T00:57:46.630+0000 I CONTROL [initandlisten] distmod: debian71
db_1 | 2015-12-22T00:57:46.630+0000 I CONTROL [initandlisten] distarch: x86_64
db_1 | 2015-12-22T00:57:46.630+0000 I CONTROL [initandlisten] target_arch: x86_64
db_1 | 2015-12-22T00:57:46.630+0000 I CONTROL [initandlisten] options: {}
db_1 | 2015-12-22T00:57:46.642+0000 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
db_1 | 2015-12-22T00:57:46.643+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
db_1 | 2015-12-22T00:57:47.829+0000 I CONTROL [initandlisten]
db_1 | 2015-12-22T00:57:47.830+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
db_1 | 2015-12-22T00:57:47.830+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
db_1 | 2015-12-22T00:57:47.830+0000 I CONTROL [initandlisten]
db_1 | 2015-12-22T00:57:47.830+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
db_1 | 2015-12-22T00:57:47.830+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
db_1 | 2015-12-22T00:57:47.830+0000 I CONTROL [initandlisten]
db_1 | 2015-12-22T00:57:47.833+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
db_1 | 2015-12-22T00:57:47.833+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
db_1 | 2015-12-22T00:57:47.835+0000 I NETWORK [initandlisten] waiting for connections on port 27017

最佳答案

编辑完整路径:构建:/path/to/dbseed

我不确定为什么找不到 /new_climat_final.json 文件。错误:

dbseed_1 | 2015-12-21T17:42:46.609+0000 Failed: open /new_climat_final.json: no such file or directory

但是你可以在运行时指定端口

CMD:CMD mongoimport --host db --port 27018 --db hpApiDev --collection coll --type json --file/new_climat_final.json --jsonArray

关于mongodb - 从 docker-compose 导入 mongodb 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34403112/

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