如何在Docker的后台启动railo服务

我叫Trang,我在https://registry.hub.docker.com/u/trangunghoa/railo-mysql/上创build了Docker镜像。它运行正常。 现在我创build了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 

没有命令它的工作。

我看着你的Dockerfile,并确定了问题。

您只能在Dockerfile中使用一个CMD。 (如果您使用多个CMD,旧的将覆盖)更多信息: https : //docs.docker.com/reference/builder/#cmd

您需要知道Docker不是为了在没有一点帮助的情况下运行多个进程而devise的。 我build议使用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"