You all may know that docker runs a single process when it is launched and we need to run multiple processes at its launching time if we are building an image through a docker file.
While launching the container, we can use a tool to run multiple processes which is ‘supervisor’.
Now the question arises that what a supervisor is.
A supervisor is a tool through which we can run multiple processes while building the docker image, in short, it manages multiple processes in our container.
If you want to run more than one process in your container, just install the supervisor through the docker file and run all the commands through it.
In my last blog, I was building an image called lamp with Prestashop through a docker file where I used a supervisor to run multiple processes like starting apache2, MySQL, and many other services at its startup time, I ran all the services in that container through the supervisor tool.
It is a very useful tool that reduces the time while starting a process in the container.
If you want the container and all the services to run automatically then just install the supervisor tool in your docker file and then you will be able to run multiple processes in your container.
Now the question arises of how the supervisor tool works.
Before I tell you how it works just have a look at my docker file, I am sure you will get to know how the supervisor is working.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
From ubuntu:14.04 MAINTAINER Prashant Arora prashant089@webkul.com RUN apt-get -y update RUN apt-get -y install lamp-server^ RUN mkdir -p /var/lock/apache2 /var/run/apache2 RUN apt-get install -y wget unzip vim nano gedit RUN apt-get install libapache2-mod-php5 php5-mcrypt php5-gd RUN php5enmod mcrypt RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf RUN apt-get install -y openssh-server RUN mkdir -p /var/run/sshd RUN apt-get install -y supervisor RUN mkdir -p /var/log/supervisor COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY mysql.sh /etc/mysql.sh RUN chmod +x /etc/mysql.sh COPY prestashop.zip /var/www/html/ RUN cd /var/www/html && unzip prestashop.zip RUN rm -rf /var/www/html/prestashop.zip RUN rm /var/www/html/index.html COPY adminer.php /var/www/html/prestashop/ RUN cd /var/www/html && chown -R www-data: prestashop EXPOSE 80 EXPOSE 22 EXPOSE 3306 CMD ["/usr/bin/supervisord"] |
If you see the 12th line, I am installing supervisor in it & then I made a directory in which all the logs will be generated and stored.
Now in the 14th line, I am moving a conf file – supervisor.conf on the path – (/etc/supervisor/conf.d/supervisord.conf), this file contains all the commands required to launch the container.
To know what all commands I stored in supervisord.conf just go and download it by hitting the command:-
1 |
docker pull webkul/lamp-with-prestashop |
To install the docker, please follow the below link:-
http://cloudkul.com/blog/start-your-journey-with-docker
or if you don’t want to install docker now and want to see all the files which I used in the docker file, you can get it also from GitHub, just click on the link given below:-
https://github.com/webkul/LAMP-WITH-PRESTASHOP
You will get all the files that I used in the docker file to build the container, you just download it and make it to use according to your requirement…:)