1

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

psaha4
  • 339
  • 3
  • 17

1 Answers1

0

Marathon is meant to run long-running tasks. So in your case, if you start a Docker container that does not keep listening on a specific port, meaning it exits successfully or unsuccessfully, Marathon will start it again.

For example, I started a Docker container using the simplest image hello-world. That generated more than 10 processes in Mesos UI in a matter of seconds! This was expected. Code inside Docker container was executing successfully and exiting normally. And since it exited, Marathon made sure that another instance of the app was started immediately.

On the other hand, when I start an nginx container which keeps listening on port 80, it becomes a long running task and a new task (Docker container) is spun up only when the existing container exits (successfully or unsuccessfully).

You probably need to work on the CMD section of your Dockerfile. Does the container in question keep running when started normally? That is, without Marathon - just using plain docker run? If yes, check if it keeps running in detached mode - docker run -d. If it exits, then CMD is the part you need to work on.

Dharmit
  • 5,498
  • 2
  • 27
  • 30
  • Thanks Dharmit,Yes when I run my docker container without marathon its working fine i.e it stays as a long running container even in a detached mode. So as you said the problem is with the CMD section. I have added "/bin/bash" to make it a long running container which some how not working with mesos so I have added an infinite while (non busy waiting, just a sleep for a condition) loop in the foreground which keeps my docker container alive and that trick works.The problem with frequent restart was, between one container dies and another starts up,my web server becomes unavailable. – psaha4 Jul 29 '15 at 18:02
  • 1
    BTW Dharmit can you tell me how did you use marathon to run a docker? is it through command prompt or marathon UI? – psaha4 Jul 29 '15 at 18:14
  • @psaha4: I am using command line. I create a json file and use curl to post it to the `/v2/apps` endpoint of Marathon. The while loop solution, though does the trick, doesn't look like an elegant solution. If you're going to need to execute `sh pga-setup.sh` every time, why not add it to `RUN` statement in your Dockerfile? – Dharmit Jul 30 '15 at 05:25
  • 1
    RUN will execute only during the docker building time. I need a shell file which can process some webserver files based on the env variables I will pass. So I need this when I start or run the docker. CMD will execute it during the docker run/restart. – psaha4 Jul 30 '15 at 14:36