How to start railo service in background on the Docker
I looked inside your Dockerfile and identified the problem.
You can only use one CMD inside a Dockerfile. (if you use multiple CMD the old one will override) More info : https://docs.docker.com/reference/builder/#cmd
You need to know that Docker isn't made for running multiple process without a little bit of help. I suggest using supervisord : https://docs.docker.com/articles/using_supervisord/
You can't use RUN service inside a Dockerfile, the reason is simple the command service will be executed and start a daemon, then notify the execution was successful. The temporary container will be killed (and the daemon too) and after that the change will be committed.
What your Dockerfile should look like :
FROM ubuntu:trustyMAINTAINER Trang Lee <trangunghoa@gmail.com>, Seta International Vietnam(info@setacinq.vn)#Install base packagesRUN apt-get -y updateRUN apt-get install -y openjdk-7-jre-headlessRUN apt-get install -y tomcat7 tomcat7-admin apache2 libapache2-mod-jkRUN apt-get purge -y openjdk-6-jre-headless icedtea-6-jre-cacao openjdk-6-jre-lib icedtea-6-jre-jamvmRUN apt-get install -y supervisor # config to enable .htaccessADD apache_default /etc/apache2/sites-available/000-default.confRUN a2enmod rewriteENV APACHE_RUN_USER www-dataENV APACHE_RUN_GROUP www-dataENV APACHE_LOG_DIR /var/log/apache2# start service ADD start-apache2.sh /start-apache2.shADD railo.sh /railo.shADD run.sh /run.shRUN chmod +x /*.sh#RUN sudo service apache2 start# install railoRUN apt-get install -y wgetRUN wget http://www.getrailo.org/railo/remote/download42/4.2.1.000/tomcat/linux/railo-4.2.1.000-pl2-linux-x64-installer.runRUN chmod -R 744 railo-4.2.1.000-pl2-linux-x64-installer.runRUN ./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 startRUN mkdir -p /etc/service/railoADD start-railo.sh /etc/service/railo/runRUN chmod 755 /etc/service/railo/run# EXPOSE <port>EXPOSE 80 8888#CMD ["/railo.sh"]#CMD ["/start-apache2.sh"]# Supervisord configurationRUN mkdir /var/log/supervisorADD ./supervisord.conf /etc/supervisor/conf.d/supervisord.confCMD ["/usr/bin/supervisord"]
With your supervisord.conf file looking something like that :
[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"