0

I'm trying to start the services like cron and supervisor after build and up the container, but the services don't start, I need to do manually the commands inside the container.

My intention is that these services are already running as soon as the container goes up.

I created a shell script that works for Caddy Web Server start, but don't for others services.

My init-services.sh

#!/bin/sh

/usr/bin/caddy --conf /etc/Caddyfile --log stdout
service supervisor start
service cron start

A piece of my Dockerfile

RUN apt-get update && apt-get install --no-install-recommends -y \
    wget \
    nano \
    git \
    unzip \
    iputils-ping \
    gnupg \
    supervisor \
    cron

COPY .docker/scripts/init-services.sh /usr/bin/init-services

RUN chmod +x /usr/bin/init-services

CMD ["/usr/bin/init-services"]
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Draake
  • 93
  • 1
  • 16
  • Best practice is to redesign your system to have one service per container. I'd also try to avoid installing some of the tools that won't be useful for your running service (`nano`, `git`, `ping`) and limit it to _just_ the one service you're trying to run. – David Maze Aug 01 '18 at 23:31
  • Possible duplicate of [Docker multiple entrypoints](https://stackoverflow.com/questions/18805073/docker-multiple-entrypoints) – David Maze Aug 01 '18 at 23:31

1 Answers1

0

You can achieve this by running your supervisor in foreground mode in your run command (CMD).

First create the supervisord.conf with required services. There also you need to start all services in nodaemon mode, which is foreground mode. As an example if you are going to start an apache server, within your supervisord.conf you need to set -D flag as below;
command=/bin/bash -c "/usr/local/bin/gosu root /sbin/httpd -D FOREGROUND"


The you need to copy this supervisord.conf file within your Dockerfile as below;
COPY supervisord.conf /etc/supervisord.d/supervisord.conf


Afterwards, you can start the supervisord service in foreground mode within your init-services.sh file as below;
/usr/bin/supervisord -c /etc/supervisord.d/supervisord.conf -n

chamindaindika
  • 455
  • 3
  • 15