【发布时间】:2020-01-13 09:45:37
【问题描述】:
我不确定ENTRYPOINT 和CMD 分别用于下面的Dockerfile 什么。
FROM mongo:3.4-xenial
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-get install zip \
unzip
RUN apt-get install -y default-jdk
RUN apt-get update -y && \
apt-get clean
RUN mkdir -p /opt/project
COPY ./project-repo/target/project-repo.zip /opt/project
WORKDIR /opt/project
RUN unzip project-repo.zip
ENTRYPOINT echo '#!/bin/bash\n\
pidfile="${TMPDIR:-/tmp}/docker-entrypoint-temp-mongod.pid" \n\
rm -f "$pidfile" \n\
# start MongoDB here \n\
mongod --logpath /var/log/mongodb.log --dbpath /data/db/ --fork --pidfilepath "$pidfile" \n\
mongo=( mongo --host 127.0.0.1 --port 27017 --quiet ) \n\
# check to see that our "mongod" actually did start up (catches "--help", "--version", MongoDB 3.2 being silly, slow prealloc, etc) \n\
# https://jira.mongodb.org/browse/SERVER-16292 \n\
tries=30 \n\
while true; do \n\
if ! { [ -s "$pidfile" ] && ps "$(< "$pidfile")" &> /dev/null; }; then \n\
# bail ASAP if "mongod" is not even running \n\
echo >&2 \n\
echo >&2 "error: mongod does not appear to have stayed running -- perhaps it had an error?" \n\
echo >&2 \n\
exit 1 \n\
fi \n\
if mongo admin --eval "quit(0)" &> /dev/null; then \n\
# success! \n\
break \n\
fi \n\
(( tries-- )) \n\
if [ "$tries" -le 0 ]; then \n\
echo >&2 \n\
echo >&2 "error: mongod does not appear to have accepted connections quickly enough -- perhaps it had an error?" \n\
echo >&2 \n\
exit 1 \n\
fi \n\
sleep 1 \n\
done \n\
mongo -- admin <<-EOF \n\
db.createUser({user:"user", pwd:"admin123", roles:[{role:"root", db:"admin"}]}); \n\
EOF' >> ./init_mongo.sh && chmod +x ./init_mongo.sh && ./init_mongo.sh && \
chmod +x /opt/project/setup.sh && /opt/project/setup.sh all && \
chmod +x /opt/project/start.sh && /opt/project/start.sh all
EXPOSE 8080
CMD ["echo 'Welcome to Demo'"]
我的 MongoDB 初始化是基于标准图像提供的。他们使用mongod 作为CMD。
我需要一些东西 - 启动 mongo,创建用户然后运行我的脚本 - 设置并启动。
没有错误。然而,在ENTRYPOINT 完成它的事情之后,容器就退出了。我希望它继续运行!!!
我猜我的CMD 是错误的。请指教。
谢谢
【问题讨论】:
标签: mongodb docker dockerfile