{"id":26511,"date":"2015-09-16T12:47:02","date_gmt":"2015-09-16T07:17:02","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=26511"},"modified":"2015-09-16T13:35:47","modified_gmt":"2015-09-16T08:05:47","slug":"dockerizing-nginx-and-ssh-using-supervisord","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/dockerizing-nginx-and-ssh-using-supervisord\/","title":{"rendered":"Dockerizing Nginx and SSH using Supervisord"},"content":{"rendered":"<p>While working with <a title=\"Docker DevOps\" href=\"http:\/\/www.tothenew.com\/devops-chef-puppet-docker\">Docker<\/a>, I came across a use case wherein I was supposed to implement two processes in a single docker container. Docker has a limitation that only one CMD parameter can be provided in the Dockerfile as only one process can be run in the foreground. The use case included running Nginx and SSH on a single docker container that by far seem to be achievable only by passing shell script in CMD parameter of Dockerfile. After a rigorous search on the internet, I found a utility Supervisor by virtue of which we can run more than one process in a Docker container without having to worry about single CMD parameter or using shell scripts.<\/p>\n<p>&#8220;The Supervisor is a process control and monitoring tool that can be used to control multiple processes on UNIX-like OS.&#8221;<\/p>\n<p>To progress with this blog, above\u00a0use case\u00a0has been detailed below. The workaround actually included two files and both the files should be kept at the same location.<\/p>\n<p>1) The Dockerfile that will run Supervisord in the foreground<br \/>\n2) supervisord.conf file that has to be passed in the Dockerfile in which we can tell multiple processes to be run inside Docker container.<\/p>\n<p><strong>Dockerfile:<\/strong><\/p>\n<p>[shell]FROM ubuntu:14.04<br \/>\nMAINTAINER sharad &amp;lt;sharad.aggarwal@tothenew.com&amp;gt;<br \/>\nRUN apt-get update &amp;amp;&amp;amp; apt-get install -y openssh-server apache2 supervisor nginx<br \/>\nRUN mkdir -p \/var\/lock\/apache2 \/var\/run\/apache2 \/var\/run\/sshd \/var\/log\/supervisor<br \/>\nRUN echo &#8216;root:password&#8217; | chpasswd<br \/>\nRUN sed -i &#8216;s\/PermitRootLogin without-password\/PermitRootLogin yes\/&#8217; \/etc\/ssh\/sshd_config<br \/>\nCOPY supervisord.conf \/etc\/supervisor\/conf.d\/supervisord.conf<br \/>\nEXPOSE 22 80 443<br \/>\nCMD [&quot;\/usr\/bin\/supervisord&quot;][\/shell]<\/p>\n<p>&nbsp;<\/p>\n<p><strong>supervisord.conf<\/strong><\/p>\n<p>[shell][supervisord]<br \/>\nnodaemon=true<\/p>\n<p>[program:sshd]<br \/>\ncommand=\/usr\/sbin\/sshd -D<\/p>\n<p>[program:nginx]<br \/>\ncommand=\/usr\/sbin\/nginx -g &quot;daemon off;&quot;<br \/>\npriority=900<br \/>\nstdout_logfile= \/dev\/stdout<br \/>\nstdout_logfile_maxbytes=0<br \/>\nstderr_logfile=\/dev\/stderr<br \/>\nstderr_logfile_maxbytes=0<br \/>\nusername=www-data<br \/>\nautorestart=true[\/shell]<\/p>\n<p>&nbsp;<\/p>\n<p>Now, run the below command to create an image to be created using above files. This command should be executed from the same location where above files are kept:<\/p>\n<p>[shell]docker build -t sharry\/supervisor-nginx-ssh .[\/shell]<\/p>\n<p>This command will take sometime to fetch necessary packages from apt repositories and building an image. Below command will show the newly created image in the image list:<\/p>\n<p>[shell]docker images[\/shell]<\/p>\n<p>Now, launch a container from this image using below command:<\/p>\n<p>[shell]docker run -itd &#8211;name nginx-ssh-test sharry\/supervisor-nginx-ssh[\/shell]<\/p>\n<p>&nbsp;<\/p>\n<p>And a new container is launched with Nginx and SSH successfully running into it. The output will be as shown in the screenshot below:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-26519\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/09\/docker-Screenshot-from-2015-09-12-003446.png\" alt=\"docker-Screenshot from 2015-09-12 00:34:46\" width=\"636\" height=\"664\" \/><\/p>\n<p>In the above screenshot, we perform SSH in the Docker container and checked the status of Nginx service. I hope this blog will be helpful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While working with Docker, I came across a use case wherein I was supposed to implement two processes in a single docker container. Docker has a limitation that only one CMD parameter can be provided in the Dockerfile as only one process can be run in the foreground. The use case included running Nginx and [&hellip;]<\/p>\n","protected":false},"author":176,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":60},"categories":[2348],"tags":[2375,2372,2373,2374,2371,2376],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/26511"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/176"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=26511"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/26511\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=26511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=26511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=26511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}