Skip to content

An opinionated centos docker image to be used as a base. Inspired from phusion baseimage (but for centos). Provides S6 process manager, rsyslog, cronie, logger, logrotate in a configurable way.

License

Notifications You must be signed in to change notification settings

thefab/docker-centos-opinionated

Repository files navigation

docker-centos-opinionated

Travis Docker Pulls DockerHub License Maturity Maintenance

Features

This repository holds an opinionated centos (version 6) docker image to be used as a base docker image. Some inspiration sources are given at the end of this file.

Features:

  • Updated image (at build time)
  • Reasonable size (106MB compressed on the hub), reasonable number of layers (9) with a squashed Dockerfile (and another one to debug)
  • Don't add too many packages by recompiling and installing just what's needed
  • Don't break the upstream system :
    • rebuild cronie et rsyslog7 from "upstream source RPM" (with some tuning to avoid too much dependencies in docker context)
    • tricks to avoid distribution interferences (hidden virtualenv in non-standard prefix)
  • Init system and multiple processes launcher/supervisor (S6)
  • (optional) syslog daemon (rsyslog) and logger binary, can store locally or forward to another syslog with a simple environnement variable
  • (optional) complete cron/anacron daemon (cronie)
  • logrotate system
  • Add epel yum repository but disabled by default (just add --enablerepo=epel to your yum commands to use it)
  • Install envtpl generic tool to be able to automatically adjust configuration files from environnement

Non-Features

  • we don't want a SSH daemon

Usage and configuration

Not really usefull (because it's mainly a base image to use in the FROM keyword) but you can play with it with (for example):

docker run -i -t thefab/centos-opinionated:latest bash

Available environnement variables:

  • DCO_CRONIE_START (if "1" (default) then starts the cron daemon)
  • DCO_RSYSLOG_START (if "1" (default) then starts the syslog daemon)
  • DCO_RSYSLOG_REMOTE_HOST (if "null" (default) then don't send logs to another syslog daemon, else forward logs to this hostname)
  • DCO_RSYSLOG_REMOTE_PORT (the remote UDP port of the (optional) remote syslog daemon, default value: 514)
  • DCO_RSYSLOG_LOCAL_FILES (if "1" (default) then log to local files in /var/log)

FAQ

How to override this image to add your service on top of it ?

When you start this image with the default "entrypoint" (/init), it launch the S6 process supervisor (see links at the end) provided by the s6-overlay.

First, it executes /etc/cont-init.d/* initialization (short) tasks. Then, it launchs /etc/services/*/run script. This script must execute your daemon in a long-lived way and will have to deal with signals. If this "run script" exits, it will be automatically restarted. An easy way to write a such script is to use the "exec" bash builtin with the "foreground mode" startup command of your service.

For example:

#!/bin/sh

exec /sbin/rsyslogd -n

Because of "exec", the script will be replaced by the launched command. So you won't have to deal with signals by yourself.

So a complete example to override this image with a new service on top of it can be:

$ find my_image

my_image/
my_image/Dockerfile
my_image/root
my_image/root/etc
my_image/root/etc/cont-init.d
my_image/root/etc/cont-init.d/my_initialization_script
my_image/root/etc/services.d
my_image/root/etc/services.d/myapp
my_image/root/etc/services.d/myapp/run

With my_image/Dockerfile like:

FROM thefab/centos-opinionated

COPY root /

And that's all ! Your custom service will be executed as well as rsyslog, cron services provides by the base image.

Can i use CMD with the init entrypoint ?

Yes, quotted from the s6-overlay README:

Using CMD is a really convenient way to take advantage of the s6-overlay. Your CMD can be given at build-time in the Dockerfile, or at runtime on the command line, either way is fine - it will be run under the s6 supervisor, and when it fails or exits, the container will exit. You can even run interactive programs under the s6 supervisor!

Please consult s6-overlay REAME for examples and more details.

Why I can't access to my environnement variables in my services script ?

Because of S6 overlay. If you want to use environnement variables in your scripts, you have to change your shebang to use the "with-contenv" S6 helper.

Example 1 (won't work):

#!/bin/bash

# don't work example

do_something_with ${MY_CONTAINER_ENV}

Example 2 (will work):

#!/usr/bin/with-contenv bash

do_something_with ${MY_CONTAINER_ENV}

What about CentOS 7 version ?

This repository is only about CentOS 6 version.

A slightly different version of this repository for CentOS 7 is available at:

https://github.com/metwork-framework/docker-centos7-opinionated

(some) Inspiration sources

About

An opinionated centos docker image to be used as a base. Inspired from phusion baseimage (but for centos). Provides S6 process manager, rsyslog, cronie, logger, logrotate in a configurable way.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published