frequent restart - docker containers in marathon/mesos

时间:2015-07-28 16:53:33

标签: docker mesos mesosphere marathon

I have been successful till completely dockerizing my webserver application. Now I want to explore more by deploying them directly to a mesos slave through marathon framework. I can deploy a docker container in to a marathon in two different approaches , either command line or through marathon web UI. Both worked for me but challenge is when I am trying to deploy my docker image, marathon frequently restarting a job and in mesos UI page I can see many finished job for the same container. Close to 10 tasks per minute. Which is not expected I believe.

My docker file looks like below:

FROM ubuntu:latest

#---------- file Author / Maintainer
MAINTAINER "abc"

#---------- update the repository sources list
RUN apt-get update && apt-get install -y \
apache2 \
curl \
openssl \
php5 \
php5-mcrypt \
unzip  

#--------- installing  composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN a2enmod rewrite

#--------- modifying the 000default file
COPY ./ /var/www/airavata-php-gateway
WORKDIR /etc/apache2/sites-available/ 
RUN sed -i 's/<\/VirtualHost>/<Directory "\/var\/www"> \n AllowOverride All \n <\/Directory> \n <\/VirtualHost>/g'  000-default.conf 
RUN sed -i 's/DocumentRoot \/var\/www\/html/DocumentRoot \/var\/www/g'  000-default.conf

WORKDIR /etc/php5/mods-available/ 
RUN sed -i 's/extension=mcrypt.so/extension=\/usr\/lib\/php5\/20121212\/mcrypt.so/g' mcrypt.ini 
WORKDIR /var/www/airavata-php-gateway/
RUN php5enmod mcrypt

#--------- making storage folder writable
RUN chmod -R 777 /var/www/airavata-php-gateway/app/storage

#-------- starting command
CMD ["sh", "-c", "sh pga-setup.sh ; service apache2 restart ; /bin/bash"]

#--------- exposing apache to default port
EXPOSE 80

Now I am clueless how to resolve this issue,any guidance will be highly appreciated. Thanks

1 个答案:

答案 0 :(得分:0)

Marathon旨在运行长时间运行的任务。所以在你的情况下,如果你启动一个没有继续监听特定端口的Docker容器,意味着它成功退出或失败,Marathon将再次启动它。

例如,我使用最简单的图像hello-world启动了Docker容器。这在几秒钟内就可以在Mesos UI中生成10多个进程!这是预料之中的。 Docker容器中的代码正在成功执行并正常退出。自从它退出后,Marathon确保应用程序的另一个实例立即启动。

另一方面,当我启动一个持续监听端口80的nginx容器时,它变成一个长时间运行的任务,只有当现有容器退出(成功或不成功)时才会启动新任务(Docker容器)。

您可能需要处理Dockerfile的CMD部分。正常启动时,有问题的容器是否继续运行?也就是说,没有马拉松 - 只使用普通的docker run?如果是,请检查它是否继续以分离模式运行 - docker run -d。如果它退出,则CMD是您需要处理的部分。