我有一个在Traefik反向代理下带有CouchDB容器的项目。
这是我的docker-compose.yml
文件:
version: '3'
services:
db:
image: couchdb:2
environment:
- COUCHDB_USER
- COUCHDB_PASSWORD
labels:
- traefik.enable=true
- traefik.backend=couchdb
- traefik.frontend.rule=Host:db.${APP_HOST}
- traefik.docker.network=app-internal
- traefik.port=5984
networks:
- server
volumes:
- couchdb_data:/opt/couchdb/data
- couchdb_config:/opt/couchdb/etc
networks:
server:
external:
name: app-internal
volumes:
couchdb_data: {}
couchdb_config: {}
我可以使用docker-compose up -d
成功启动容器,但是每次发出请求时,都会收到502 Bad Gateway错误。
如果我运行docker-compose logs -f
,我只会得到:
Attaching to app_db_1
但是大约2分钟后,我得到了这样的日志:
Attaching to app_db_1
db_1 | [info] 2018-07-29T04:38:45.002045Z nonode@nohost <0.7.0> -------- Application couch_log started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:45.006960Z nonode@nohost <0.7.0> -------- Application folsom started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:45.076415Z nonode@nohost <0.7.0> -------- Application couch_stats started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:45.076561Z nonode@nohost <0.7.0> -------- Application khash started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:45.086425Z nonode@nohost <0.7.0> -------- Application couch_event started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:45.095918Z nonode@nohost <0.7.0> -------- Application ibrowse started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:45.104024Z nonode@nohost <0.7.0> -------- Application ioq started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:45.106795Z nonode@nohost <0.7.0> -------- Application mochiweb started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:45.116667Z nonode@nohost <0.195.0> -------- Apache CouchDB 2.1.2 is starting.
db_1 |
db_1 | [info] 2018-07-29T04:38:45.119537Z nonode@nohost <0.196.0> -------- Starting couch_sup
db_1 | [info] 2018-07-29T04:38:45.366272Z nonode@nohost <0.47.0> -------- alarm_handler: {set,{system_memory_high_watermark,[]}}
db_1 | [info] 2018-07-29T04:38:46.174267Z nonode@nohost <0.195.0> -------- Apache CouchDB has started. Time to relax.
db_1 |
db_1 | [info] 2018-07-29T04:38:46.174398Z nonode@nohost <0.195.0> -------- Apache CouchDB has started on http://any:5986/
db_1 | [info] 2018-07-29T04:38:46.174571Z nonode@nohost <0.7.0> -------- Application couch started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:46.174743Z nonode@nohost <0.7.0> -------- Application ets_lru started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:46.287113Z nonode@nohost <0.7.0> -------- Application rexi started on node nonode@nohost
db_1 | [error] 2018-07-29T04:38:46.341609Z nonode@nohost emulator -------- Error in process <0.265.0> with exit value: {badarg,[{ets,member,[mem3_openers,<<11 bytes>>],[]},{mem3_shards,maybe_spawn_shard_writer,3,[{file,"src/mem3_shards.erl"},{line,486}]},{mem3_shards,load_shards_from_db,2,[{file,"src/mem3_shards.erl"},{line,389}]},{mem3_shards,load_shards_from_disk...
db_1 | [error] 2018-07-29T04:38:46.342196Z nonode@nohost <0.248.0> -------- Error opening view group `_replicator` from database `shards/80000000-9fffffff/_replicator.1532833386`: {'EXIT',{{badmatch,{badarg,[{ets,member,[mem3_openers,<<"_replicator">>],[]},{mem3_shards,maybe_spawn_shard_writer,3,[{file,"src/mem3_shards.erl"},{line,486}]},{mem3_shards,load_shards_from_db,2,[{file,"src/mem3_shards.erl"},{line,389}]},{mem3_shards,load_shards_from_disk,1,[{file,"src/mem3_shards.erl"},{line,378}]},{mem3_shards,load_shards_from_disk,2,[{file,"src/mem3_shards.erl"},{line,407}]},{mem3_shards,for_docid,3,[{file,"src/mem3_shards.erl"},{line,96}]},{fabric_doc_open,go,3,[{file,"src/fabric_doc_open.erl"},{line,38}]},{couch_index_server,'-get_index/3-fun-0-',2,[{file,"src/couch_index_server.erl"},{line,68}]}]}},[{couch_mrview,get_info,2,[{file,"src/couch_mrview.erl"},{line,332}]},{couch_compaction_daemon,maybe_compact_view,3,[{file,"src/couch_compaction_daemon.erl"},{line,253}]},{couch_compaction_daemon,maybe_compact_views,3,[{file,"src/couch_compaction_daemon.erl"},{line,227}]},{couch_compaction_daemon,'-compact_loop/1-fun-0-',3,[{file,"src/couch_compaction_daemon.erl"},{line,141}]},{couch_server,'-all_databases/2-fun-0-',4,[{file,"src/couch_server.erl"},{line,278}]},{filelib,do_fold_files2,8,[{file,"filelib.erl"},{line,184}]},{filelib,do_fold_files2,8,[{file,"filelib.erl"},{line,194}]},{couch_server,all_databases,2,[{file,"src/couch_server.erl"},{line,267}]}]}}
db_1 | [error] 2018-07-29T04:38:46.730749Z nonode@nohost emulator -------- Error in process <0.310.0> with exit value: {badarg,[{ets,member,[mem3_openers,<<6 bytes>>],[]},{mem3_shards,maybe_spawn_shard_writer,3,[{file,"src/mem3_shards.erl"},{line,486}]},{mem3_shards,load_shards_from_db,2,[{file,"src/mem3_shards.erl"},{line,389}]},{mem3_shards,load_shards_from_disk...
db_1 | [error] 2018-07-29T04:38:46.732051Z nonode@nohost <0.248.0> -------- Error opening view group `_auth` from database `shards/40000000-5fffffff/_users.1532833374`: {'EXIT',{{badmatch,{badarg,[{ets,member,[mem3_openers,<<"_users">>],[]},{mem3_shards,maybe_spawn_shard_writer,3,[{file,"src/mem3_shards.erl"},{line,486}]},{mem3_shards,load_shards_from_db,2,[{file,"src/mem3_shards.erl"},{line,389}]},{mem3_shards,load_shards_from_disk,1,[{file,"src/mem3_shards.erl"},{line,378}]},{mem3_shards,load_shards_from_disk,2,[{file,"src/mem3_shards.erl"},{line,407}]},{mem3_shards,for_docid,3,[{file,"src/mem3_shards.erl"},{line,96}]},{fabric_doc_open,go,3,[{file,"src/fabric_doc_open.erl"},{line,38}]},{couch_index_server,'-get_index/3-fun-0-',2,[{file,"src/couch_index_server.erl"},{line,68}]}]}},[{couch_mrview,get_info,2,[{file,"src/couch_mrview.erl"},{line,332}]},{couch_compaction_daemon,maybe_compact_view,3,[{file,"src/couch_compaction_daemon.erl"},{line,253}]},{couch_compaction_daemon,maybe_compact_views,3,[{file,"src/couch_compaction_daemon.erl"},{line,227}]},{couch_compaction_daemon,'-compact_loop/1-fun-0-',3,[{file,"src/couch_compaction_daemon.erl"},{line,141}]},{couch_server,'-all_databases/2-fun-0-',4,[{file,"src/couch_server.erl"},{line,278}]},{filelib,do_fold_files2,8,[{file,"filelib.erl"},{line,184}]},{filelib,do_fold_files2,8,[{file,"filelib.erl"},{line,194}]},{couch_server,all_databases,2,[{file,"src/couch_server.erl"},{line,267}]}]}}
db_1 | [info] 2018-07-29T04:38:46.792070Z nonode@nohost <0.7.0> -------- Application mem3 started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:46.792258Z nonode@nohost <0.7.0> -------- Application fabric started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.038648Z nonode@nohost <0.7.0> -------- Application chttpd started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.058860Z nonode@nohost <0.7.0> -------- Application couch_index started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.058951Z nonode@nohost <0.7.0> -------- Application couch_mrview started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.058997Z nonode@nohost <0.7.0> -------- Application couch_plugins started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.078801Z nonode@nohost <0.373.0> -------- Opening index for db: _users idx: _design/_auth sig: "3e823c2a4383ac0c18d4e574135a5b08"
db_1 | [info] 2018-07-29T04:38:47.183364Z nonode@nohost <0.404.0> -------- Opening index for db: _replicator idx: _design/_replicator sig: "3e823c2a4383ac0c18d4e574135a5b08"
db_1 | [notice] 2018-07-29T04:38:47.267666Z nonode@nohost <0.82.0> -------- config: [features] scheduler set to true for reason nil
db_1 | [info] 2018-07-29T04:38:47.301691Z nonode@nohost <0.7.0> -------- Application couch_replicator started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.316926Z nonode@nohost <0.7.0> -------- Application couch_peruser started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.340586Z nonode@nohost <0.7.0> -------- Application ddoc_cache started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.359635Z nonode@nohost <0.7.0> -------- Application global_changes started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.359675Z nonode@nohost <0.7.0> -------- Application jiffy started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.369212Z nonode@nohost <0.7.0> -------- Application mango started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.373713Z nonode@nohost <0.7.0> -------- Application setup started on node nonode@nohost
db_1 | [info] 2018-07-29T04:38:47.373771Z nonode@nohost <0.7.0> -------- Application snappy started on node nonode@nohost
在那之后,我可以成功地向数据库发出请求
我已经测试了很多次,总是要花2分钟左右。
有人知道为什么会这样吗?
谢谢。
更新: 我在没有Traefik的情况下运行它,但我仍然遇到相同的问题
答案 0 :(得分:0)
我知道我来晚了,但是今天在创建一个脚本来测试我的CouchDB备份时遇到了同样的问题。经过一番调查,我发现延迟的根源是docker-entrypoint.sh
脚本中的一行,该脚本更新了容器中/opt/couchdb
树中文件的所有权。这是一行:
find /opt/couchdb \! \( -user couchdb -group couchdb \) -exec chown -f couchdb:couchdb '{}' +
在容器的第一次启动过程中,此命令必须更新1600多个文件。取决于您的容器主机和主机文件系统,这可能需要一些时间。
在CouchDB项目解决此问题之前,您可以使用以下Dockerfile派生自己的优化容器:
FROM couchdb:latest
RUN find /opt/couchdb \! \( -user couchdb -group couchdb \) -exec chown -c couchdb:couchdb '{}' +
使用该容器映像作为我的测试容器的基础,我能够将初始启动时间从> 50秒减少到3秒。