How to get started with a rail in the background on Docker

My name is Trang, I created a Docker image at https://registry.hub.docker.com/u/trangunghoa/railo-mysql/ It works fine. Now I have created a Dockerfile, but I cannot start the automatic Railo maintenance. Please help me. I am running some commands in a shell script:

exec /opt/railo/railo_ctl start
exec /opt/railo/railo_ctl start -D FOREGROUND
service railo_ctl restart
exec service railo_ctl restart

      

No command works.

+3


source to share


1 answer


I looked into your Dockerfile and spotted the problem.

You can only use one CMD inside a Dockerfile. (if you are using multiple CMDs the old one will override) More info: https://docs.docker.com/reference/builder/#cmd

You need to know that Docker is not designed to run multiple processes without a little help. I suggest using supervisord: https://docs.docker.com/articles/using_supervisord/

You cannot use the RUN service inside the Dockerfile, the reason is simple that the command service will start and start the daemon, and then report that the execution was successful. The temporary container will be killed (and the daemon too), after which the change will be performed.



What your Dockerfile should look like:

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"]

      

With your supervisord.conf file looking something like this:

[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"

      

+6


source







All Articles