2

I've made a (docker) container for ddclient.

The problem is that I'm having problems in running that service in the foreground so that the docker container keeps running.

I've managed to keep the docker running by adding a bashat the end of the script but this is hackish, since the actual process it should be whatching is the ddclient.

Another way I found was to tail -f the log file, but if the service stops, the container will keep running instead of stoping.

Q: So is there any (easy) way to keep a service running in the foreground?

mloureiro
  • 957
  • 1
  • 12
  • 34

1 Answers1

0

The problem with the process (any process) running in a container is signal management: you need to make sure the SIGKILL and other signals are properly communicated to the right process(es) in order to successfully stop/remove a container (and not leave zombie processes: see "PID 1 zombie reaping issue")

One option is at least to make your service at least write in a log file

ENTRYPOINT ["/bin/sh" "-c" ]
CMD  yourProcess > log

That should keep it in foreground, as suggested in "How do I bring a daemon process to foreground?".

For a service, try and use as a base image phusion/baseimage-docker which manages other services properly.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'm starting the process as ubuntu service, like `service ddclient start` so, this doesn't any output – mloureiro Jan 12 '16 at 16:04
  • @mloureiro I have eidted the answer – VonC Jan 12 '16 at 16:06
  • Thanks @VonC, but I'm already using that image... After reading all that, and actually take a look at the *my_init* script. I don't understand how this is supposed to help me. And about the daemon `mydaemon > /var/log/mydaemonlogfile` if I do `service ddclient start > /var/log/ddclient.log` how does this help? – mloureiro Jan 12 '16 at 19:37
  • @mloureiro It helps the process staying in foreground. But if the service start ends immediately, that won't help. Could you do (as in http://stackoverflow.com/a/26735742/6309) a `service ddclient start && service supervisor start`? – VonC Jan 12 '16 at 19:46
  • @mloureiro that base image should still being able to help you: http://stackoverflow.com/a/25775424/6309. "runit will stay online while Nginx and Supervisor run" (in your case while ddclient runs) – VonC Jan 12 '16 at 19:48
  • I don't have `supervisor` on the container, should it come with `baseimage` or do I need to install it? – mloureiro Jan 14 '16 at 10:09
  • @mloureiro you don't need to the supervisor, just to us the https://github.com/phusion/baseimage-docker and its runit main service: you can declare ddclient as a service. – VonC Jan 14 '16 at 10:13
  • i'm using `phusion/baseimage:0.9.18` how can I *declare ddclient as a service* ? – mloureiro Jan 14 '16 at 12:09
  • 1
    @mloureiro As documented: https://github.com/phusion/baseimage-docker#adding_additional_daemons – VonC Jan 14 '16 at 12:14