gpt4 book ai didi

mongodb - CMD dockerfile未执行

转载 作者:行者123 更新时间:2023-12-02 20:39:16 26 4
gpt4 key购买 nike

我创建了一个docker镜像以播种我的dockerized mongo实例:

FROM mongo:2.6
MAINTAINER Living Digital Way
COPY ./clients.init.json .
COPY ./users.init.json .

CMD mongoimport --host mongo --db lvdb --collection clients --type json --file ./clients.init.json --jsonArray --upsert --upsertFields client_id
CMD mongoimport --host mongo --db lvdb --collection users --type json --file ./users.init.json --jsonArray --upsert --upsertFields username

我首先开始我的mongo实例:
docker run --name mongo -p 27017:27017 --hostname mongo mongo:2.6

之后,我执行我的图像:
docker run --link mongo:mongo registry.private.com/mongo_seed:demo

这是输出:
# docker run --name mongo-seed --link mongo:mongo registry.private.com/mongo-seed:demo
Unable to find image 'registry.private.com/mongo-seed:demo' locally
v1: Pulling from mongo-seed
046d0f015c61: Already exists
ba95eb02831f: Already exists
53dc8636c4de: Already exists
a1ba40c46d70: Already exists
58b7d37cc7a7: Already exists
6fc4041cef29: Already exists
4cb494f83a39: Already exists
29839a673e80: Pull complete
cc731752cc1a: Pull complete
Digest: sha256:9a88d141b426fb7e96d2418f63c1587f6c055602d77c13ddd4ef744d66d6acc2
Status: Downloaded newer image for registry.private.com/mongo-seed:demo
connected to: mongo
2016-09-09T12:11:42.194+0000 imported 1 objects <<<<<<<<<<<<<<<<

如您所见,仅执行最后一个 CMD

难道我做错了什么?

最佳答案

Dockerfile中只能有一个CMD指令。如果您列出多个CMD,则只有最后一个CMD才会生效。我建议您将这两个命令放在单独的import.sh中,将其复制到您的容器中,然后使用CMD运行它。

COPY ./clients.init.json .
COPY ./users.init.json .
COPY ./import.sh .
RUN ["chmod", "+x", "import.sh"] # -> only required, if import.sh is not executable

CMD ["import.sh"]

关于mongodb - CMD dockerfile未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39411523/

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