扩展CouchDB Docker映像 [英] Extending CouchDB Docker image

查看:55
本文介绍了扩展CouchDB Docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试扩展CouchDB docker映像以预填充CouchDB(带有初始数据库,设计文档等)。

I’m trying to extend CouchDB docker image to pre-populate CouchDB (with initial databases, design documents, etc.).

为了创建名为 db 的数据库,我首先尝试了此初始 Dockerfile

In order to create a database named db, I first tried this initial Dockerfile:

FROM couchdb
RUN curl -X PUT localhost:5984/db

,但是构建失败,因为在构建时尚未启动ouchdb服务。因此,我将其更改为:

but the build failed since couchdb service is not yet started at build time. So I changed it into this:

FROM couchdb
RUN service couchdb start && \ 
  sleep 3 && \                 
  curl -s -S -X PUT localhost:5984/db && \
  curl -s -S localhost:5984/_all_dbs

注意:


  • 睡眠是我发现使其工作的唯一方法,因为它不工作使用curl选项-connect-timeout

  • 第二个 curl 是只是检查数据库是否已创建。

  • the sleep was the only way I found to make it work, since it did not work with curl option --connect-timeout,
  • the second curl is only to check that the database was created.

该构建似乎可以正常工作:

The build seems to work fine:

$ docker build . -t test3 --no-cache
Sending build context to Docker daemon  6.656kB
Step 1/2 : FROM couchdb
 ---> 7f64c92d91fb
Step 2/2 : RUN service couchdb start &&   sleep 3 &&   curl -s -S -X PUT localhost:5984/db &&   curl -s -S localhost:5984/_all_dbs
 ---> Running in 1f3b10080595
Starting Apache CouchDB: couchdb.
{"ok":true}
["db"]
Removing intermediate container 1f3b10080595
 ---> 7d733188a423
Successfully built 7d733188a423
Successfully tagged test3:latest

奇怪的是现在,当我将其作为容器启动时,数据库 db 似乎没有保存到 test3 映像中:

What is weird is that now when I start it as a container, database db does not seem to be saved into test3 image:

$ docker run -p 5984:5984 -d test3
b34ad93f716e5f6ee68d5b921cc07f6e1c736d8a00e354a5c25f5c051ec01e34

$ curl localhost:5984/_all_dbs
[]


推荐答案

大多数标准Docker数据库映像包含 VOLUME 行,该行可防止使用预填充的数据创建派生映像。对于官方 couchdb 图片,您可以参见中的相关行Dockerfile 。与关系数据库图像不同,该图像不支持首次启动时运行的脚本。

Most of the standard Docker database images include a VOLUME line that prevents creating a derived image with prepopulated data. For the official couchdb image you can see the relevant line in its Dockerfile. Unlike the relational-database images, this image doesn’t have any support for scripts that run at first startup.

这意味着您需要从主机或另一个容器进行初始化。如果您可以使用其HTTP API直接与它进行交互,则它可能类似于:

That means you need to do the initialization from the host or from another container. If you can directly interact with it using its HTTP API, then this could look like:

# Start the container
docker run -d -p 5984:5984 -v ... couchdb

# Wait for it to be up
for i in $(seq 20); do
  if curl -s http://localhost:5984 >/dev/null 2>&1; then
    break
  fi
  sleep 1
done

# Create the database
curl -XPUT http://localhost:5984/db

这篇关于扩展CouchDB Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆