我叫Trang, 我在https://registry.hub.docker.com/u/trangunghoa/railo-mysql/上创建了Docker镜像 运行正常。 现在我创建了Dockerfile,但我无法启动自动Railo服务。请帮我。 我从shell脚本的一些命令开始:
exec /opt/railo/railo_ctl start
exec /opt/railo/railo_ctl start -D FOREGROUND
service railo_ctl restart
exec service railo_ctl restart
没有命令可行。
答案 0 :(得分:6)
我查看了你的Dockerfile并发现了问题。
您只能在Dockerfile中使用一个CMD。 (如果您使用多个CMD,旧的CMD将覆盖)更多信息:https://docs.docker.com/reference/builder/#cmd
你需要知道Docker并没有在没有一点帮助的情况下运行多个进程。我建议使用supervisord:https://docs.docker.com/articles/using_supervisord/
你不能在Dockerfile中使用RUN服务,原因很简单,命令服务将被执行并启动一个守护进程,然后通知执行成功。
,将会杀死临时容器(以及守护进程),然后进行更改。您的Dockerfile应该是什么样子:
FROM ubuntu:trusty
MAINTAINER Trang Lee <trangunghoa@gmail.com>, Seta International Vietnam(info@setacinq.vn)
#Install base packages
RUN apt-get -y update
RUN apt-get install -y openjdk-7-jre-headless
RUN apt-get install -y tomcat7 tomcat7-admin apache2 libapache2-mod-jk
RUN apt-get purge -y openjdk-6-jre-headless icedtea-6-jre-cacao openjdk-6-jre-lib icedtea-6-jre-jamvm
RUN apt-get install -y supervisor
# config to enable .htaccess
ADD apache_default /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
# start service
ADD start-apache2.sh /start-apache2.sh
ADD railo.sh /railo.sh
ADD run.sh /run.sh
RUN chmod +x /*.sh
#RUN sudo service apache2 start
# install railo
RUN apt-get install -y wget
RUN wget http://www.getrailo.org/railo/remote/download42/4.2.1.000/tomcat/linux/railo-4.2.1.000-pl2-linux-x64-installer.run
RUN chmod -R 744 railo-4.2.1.000-pl2-linux-x64-installer.run
RUN ./railo-4.2.1.000-pl2-linux-x64-installer.run --mode unattended --railopass “123456”
# remove railo setup
#RUN rm -rf railo-4.2.1.000-pl2-linux-x64-installer.run
#RUN sudo service railo_ctl start
RUN mkdir -p /etc/service/railo
ADD start-railo.sh /etc/service/railo/run
RUN chmod 755 /etc/service/railo/run
# EXPOSE <port>
EXPOSE 80 8888
#CMD ["/railo.sh"]
#CMD ["/start-apache2.sh"]
# Supervisord configuration
RUN mkdir /var/log/supervisor
ADD ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
你的supervisord.conf文件看起来像这样:
[supervisord]
nodaemon=true
[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"
[program:railo]
command=/bin/bash -c "exec /opt/railo/railo_ctl start -D FOREGROUND"