Skip to content

arvindr226/supervisord

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

supervisord

Why Supervisor with Docker ?

Generally a Docker container starts with a single process when it is launched, for example an Apache daemon or a SSH server daemon. Often though you want to run more than one process in a container. There are a number of ways you can achieve this ranging from using a simple Bash script as the value of your container’s CMD instruction to installing a process management tool.

Lets start with supervisor to run multiple process in the single container.

Create a Dockerfile Choose Ubuntu LTS 16.04 default image.

From ubuntu16.04
Maintainer Arvind Rawat <arvindr226@gmail.com>

Install the apache2, openssh-server and supervisor.

RUN sudo apt get update && apt install -y apache2 openssh-server supervisor
RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor

Configure the ssh for root user in Dockerfile

RUN echo 'root:gotechnies' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

SSH login fix. Otherwise user is kicked off after login

RUN sed 's@session\srequired\spam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile" RUN echo "export VISIBLE=now" >> /etc/profile

Add a supervisor configuration file

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
The above configuration will add the supervisord.conf file inthe container while build the docker image.

Add the below content in the supervisord.conf

[supervisord]
nodaemon=true

[program:sshd] command=/usr/sbin/sshd -D

[program:apache2] command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"

Exposing ports with running Supervisor

Let's enable the required default ports to access the http (port 80) and ssh (port 22) in the Dockerfile and write a line to start supervisor execute using the CMD in Dockerfile.
EXPOSE 22 80
CMD ["/usr/bin/supervisord"]

Your Final complete Dockerfile will look like below.

From ubuntu:16.04
Maintainer Arvind Rawat <arvindr226@gmail.com>

RUN apt-get update && apt-get install -y openssh-server apache2 supervisor RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor

RUN echo 'root:gotechnies' | chpasswd RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config RUN sed 's@session\srequired\spam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile" RUN echo "export VISIBLE=now" >> /etc/profile COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf EXPOSE 22 80 CMD ["/usr/bin/supervisord"]

Now build your docker image with this Dockerfile

$ docker build -t gotechnies .

Start your docker container like below

 docker run -d -p 80:80 -p 2222:22 gotechnies

Try to connect with ssh server

$ ssh root@localhost -p 2222 

Use the password you have added in the Dockerfile.

gotechnies

Check the apache on web browser http://localhost

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published