我正在尝试扩展 CouchDB docker 镜像来预填充 CouchDB(使用初始数据库、设计文档等)。
为了创建一个名为db
,我首先尝试了这个初始Dockerfile
:
FROM couchdb
RUN curl -X PUT localhost:5984/db
但由于 couchdb 服务在构建时尚未启动,因此构建失败。所以我把它改成了这样:
FROM couchdb
RUN service couchdb start && \
sleep 3 && \
curl -s -S -X PUT localhost:5984/db && \
curl -s -S localhost:5984/_all_dbs
Note:
- the
sleep
这是我发现让它工作的唯一方法,因为它不适用于curl选项--connect-timeout
,
- 第二
curl
只是检查数据库是否已创建。
构建似乎工作正常:
$ 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
image:
$ docker run -p 5984:5984 -d test3
b34ad93f716e5f6ee68d5b921cc07f6e1c736d8a00e354a5c25f5c051ec01e34
$ curl localhost:5984/_all_dbs
[]
大多数标准 Docker 数据库镜像都包含VOLUME
阻止使用预填充数据创建派生图像的行。为了官方的couchdb image你可以看到其相关行Dockerfile。与关系数据库映像不同,此映像不支持首次启动时运行的脚本。
这意味着您需要从主机或另一个容器进行初始化。如果您可以使用其 HTTP API 直接与其交互,那么这可能如下所示:
# 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)