3

I'm trying to run 3 services at my container startup (snmpd, sshd and centengine)

As runlevel is unknown in the container, services won't start.

I built an image with this Dockerfile :

FROM centos:6.7
MAINTAINER nael <me@mail>

# Update CentOS
RUN yum -y update

# Install wget
RUN yum install -y wget

# Get Centreon Repo
RUN wget http://yum.centreon.com/standard/3.0/stable/ces-standard.repo -O /etc/yum.repos.d/ces-standard.repo

# Install Packages (SSH, sudo, Centreon Poller & Engine, SNMP)
RUN yum install -y --nogpgcheck openssh-clients openssh-server centreon-poller-centreon-engine sudo net-snmp net-snmp-utils

# Install supervisord
RUN rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN yum --enablerepo=epel install -y supervisor
RUN mv -f /etc/supervisord.conf /etc/supervisord.conf.org
ADD supervisord.conf /etc/

# For sshd & centengine
EXPOSE 22 5669

# Change user password
RUN echo -e "password" | (passwd --stdin user)

# Disable PAM (causing issues while ssh login)
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config

# Start supervisord
CMD ["/usr/bin/supervisord"]

Here is the supervisord.conf file

[supervisord]
nodaemon=true
pidfile=/var/run/supervisord.pid
logfile=/var/log/supervisor/supervisord.log

[program:centengine]
command=service centengine start

[program:snmpd]
command=service snmpd start

[program:sshd]
command=service sshd start

But with this Dockerfile and supervisord.conf, when I start my container theses services aren't running.

What could be the problem ?

Nael
  • 61
  • 1
  • 8
  • Same problem with a CMD section like you suggested EDIT: Just edited CMD section in message above. – Nael May 12 '16 at 15:51
  • I think `service ... start` does not work inside Docker containers. See http://stackoverflow.com/questions/27154567/ubuntu-12-04-into-docker-service-mysql-start for solutions using `supervisord` – Xiongbing Jin May 12 '16 at 17:01
  • Updated my conf with supervisord, still not working. I'm still using `service ... start` in my supervisord.conf but it shouldn't be a problem (the post where I found the exmple for the file was using this commands) I'll try to find a way to run the services in foreground as most of the `supervisord.conf`use this type of start : `command=/usr/sbin/sshd -D` – Nael May 13 '16 at 10:00
  • I think that my `/usr/bin/supervisord` don't start with the container. When I start the container, services aren't started. If I manually start `/usr/bin/supervisord` then the services are started. – Nael May 13 '16 at 15:16
  • Again, Docker does not support services as I now understand. You need to add `/usr/bin/supervisord` as the CMD of your container, and you need to change your supervisord.conf file to run the binary directly instead of using service as it won't work. I removed my first comment in case it might confuse people in the future. – Xiongbing Jin May 13 '16 at 15:44
  • Both with `service ... start` or binary file I always have a `INFO exited: sshd (exit status 0; not expected)` Error in supervisord. – Nael May 17 '16 at 07:44
  • Try `command=usr/sbin/sshd -D` – Xiongbing Jin May 17 '16 at 14:31
  • This is the one I'm using. – Nael May 18 '16 at 15:01

2 Answers2

1

Not anymore using supervisord.

I just include a script with all the services ... start commands in the Dockerfile. When I create my container with docker run ... I just specify that I want to start it with my script.

& that's working very well.

Thanks @warmoverflow for trying to solve this.

Nael
  • 61
  • 1
  • 8
0

You may find my dockerfy utility useful starting services, pre-running initialization commands before the primary command starts. See https://github.com/markriggins/dockerfy

For example:

RUN wget https://github.com/markriggins/dockerfy/releases/download/0.2.4/dockerfy-linux-amd64-0.2.4.tar.gz; \
    tar -C /usr/local/bin -xvzf dockerfy-linux-amd64-*tar.gz; \
    rm dockerfy-linux-amd64-*tar.gz;


ENTRYPOINT dockerfy 
COMMAND --start bash -c "while false; do echo 'Ima Service'; sleep 1; done" -- \
    --reap -- \
    nginx 

Would run a bash script as a service, echoing "Ima Service" every second, while the primary command nginx runs. If nginx exits, then the "Ima Service" script will automatically be stopped.

As an added benefit, any zombie processes left over by nginx will be automatically cleaned up.

You can also tail log files such as /var/log/nginx/error.log to stderr, edit nginx's configuration prior to startup and much more

Mark Riggins
  • 195
  • 1
  • 3
  • 5