Skip to content
Run several commands in a docker container
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example/php-nginx
test
.gitignore
.travis.yml
LICENSE
README.md
daemon.go
daemon_test.go
glide.lock
glide.yaml
hydre.go
hydre_test.go
main.go
utils.go

README.md

Hydre

unmaintained download Build Status GoDoc Test Coverage Maintainability codebeat goreport


Hydre allows you to run several commands in a docker container.

Usually you only run one process in a docker container. It is the best practice. But sometimes you may still want to run several processes in one container because :

  • the processes are tightly coupled and it is really complicated to separate them.
  • it does not bring anything more to split these processes in different containers in terms of scalability.

Use cases :

  • php and nginx
  • a small mail server (postfix + dovecot + spamassassin + amavis + clamav)

A php and nginx example is available in the example directory.

Behavior

Hydre starts several daemons. It will run as long as every daemon is working properly. When one daemon dies Hydre stops. You have to restart the container to restart the daemons.

Installation

To run Hydre you need two files :

  • the Hydre binary
  • a configuration file

It is easy to include it in a Dockerfile :

COPY hydre.yml /home/hydre.yml
ADD https://github.com/sarulabs/hydre/releases/download/2.0.1/hydre /home/hydre
RUN chmod +x /home/hydre

CMD ["/home/hydre", "-c", "/home/hydre.yml"]

Configuration file

The configuration file is in yaml format.

timeout: 3
daemons:
    myAwesomeApp:
        command: "my_awesome_app start"
    coolDaemon:
        command: "/ect/init.d/cool_daemon start"
        stopCommand: "/ect/init.d/cool_daemon stop"
        pidFile: "/var/run/cool_daemon/pid"
        logFiles: ["/var/log/cool_daemon.access", "/var/log/cool_daemon.error"]
  • timeout : time in seconds that daemons have to stop gracefully
  • daemons : the definition of the commands you want to execute
    • command : the unix command that start the program
    • stopCommand : a command to stop the daemon gracefully (optional)
    • pidFile : the path to the daemon pid file (optional)
    • logFiles : an array containing the paths to the log files (optional)

Foreground process

If you want to execute a program that runs in the foreground, you only need to specify the command parameter. If the logs are not written directly on the standard output, it is possible to stream them on the standard output of the container with the logFiles parameter.

Background process

If you want to execute a program that runs in the background (init.d scripts for example) you need to specify a pidFile. You can also set the stopCommand parameter to stop the program gracefully and avoid keeping files from shared volumes in an undesired state.

You can’t perform that action at this time.