Skip to content

Dalee/build.docker

Repository files navigation

Build Status

Tiny Docker images for painless microservices deployment

Baseimage

baseimage is inspired by phusion/baseimage-docker. It uses same directory layout for defining services, patched versions of my_init and setuser (but compatible with original one), but, build from scratch.

Integrated services

  • my_init - boot manager
  • my_wait - dependency manager, a-la wait-for-it
  • runit - process supervisor
  • nginx - reverse proxy service, disabled by default
  • msmtp - smtp relay/sendmail service, disabled by default
  • bcron - cron service, disabled by default

Container control

Integrated software

Beware, baseimage doesn't contain top and ps commands due Ubuntu's dependencies. Commands htop and pstree provided as replacements.

Defaults

  • Preconfigured locales: en_US.UTF-8, ru_RU.UTF-8
  • Default LANG/LC_ALL: en_US.UTF-8
  • Default timezone: Europe/Moscow

Container lifecycle

Boot sequence

  1. wait: /etc/my_wait.d/*
  2. run: /etc/my_init.d/*
  3. run: /etc/rc.local
  4. run: /sbin/runit
  5. wait: /etc/service/*/check

Every wait script should exit with code:

  • 0 — ready, no further call required
  • 1 — wait, subsequent call required

Global wait timeout covering all scripts in phase. Do not put sleep or loop inside of wait script, script should check condition and return asap.

Global timeout for each wait phase can be configured independently: (--wait-resources-timeout for /etc/my_wait.d/ and --wait-services-timeout for /etc/service/*/check). Default value for each timeout is 30 seconds.

If /etc/my_wait.d/* or /etc/service/*/check exceed global timeout, container will refuse to start.

Beware, due nature of script running, all checks will be executed at least once, even if one check is already violated timeout.

If any of /etc/my_init.d/*, /etc/rc.local exits with non-zero exit code, container will refuse to start.

Once all wait and run phases of boot sequence are finished, container considered alive. No further checks will run.

Shutdown sequence

For alive container, on terminate/kill signal, shutdown sequence will run:

  1. run: /etc/my_init.pre_shutdown.d/*
  2. kill: runit
  3. run: /etc/my_init.post_shutdown.d/*

Each phase will run only if previous finished gracefully.

Running as nobody / other user

/sbin/setuser username command [arguments]

Command environment will be explicitly filled with container defined environment variables. Variables filled without overwriting, so, call NODE_ENV=staging /sbin/setuser env | grep NODE_ENV will print staging no matter what is defined in /etc/container_environment/NODE_ENV.

Enabling integrated services

Cron

  • Repository: official
  • Dockerfile: RUN /sbin/enable_service cron
  • Configure: /etc/crontab

Beware, cron will run tasks with reduced set of environment variables, if your script need access to all container environment variables, run task via /sbin/setuser command.

Sample /etc/crontab file:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# script WITH container environment variables
* * * * * root /sbin/setuser nobody /app/app_cron.sh

# script WITHOUT container environment variables
* * * * * root /app/system_cleanup.sh

Sendmail / msmtp

  • Repository: official
  • Dockerfile: RUN /sbin/enable_service sendmail
  • Configure: provide environment variables on container start:
    • SENDMAIL_HOST - ip address or domain name of SMTP server
    • SENDMAIL_PORT - override smtp port, default is 25
    • SENDMAIL_DOMAIN - force outbound from:

Sample docker run command:

docker run --rm \
	-e SENDMAIL_HOST="mail.example.com" \
	...

Nginx

  • Repository: nginx/stable
  • Dockerfile: RUN /sbin/enable_service nginx
  • Configure:
    • create project config (with .conf extension) in /etc/nginx/virtuals directory
    • if default config is not suitable, just create desired /etc/nginx/nginx.conf, baseimage will not override it.

Do not use daemon off, run script will provide this option by default.

Node.JS 6

Image is squashed, so actually it contains only two layers.

  • Node.js 6 Maintenance LTS
  • Yarn

docker pull dalee/nodejs-6

Node.JS 8

Image is squashed, so actually it contains only two layers.

  • Node.js 8 Active LTS
  • Yarn

docker pull dalee/nodejs-8

PHP 5.6

Image is squashed, so actually it contains only two layers.

  • PHP 5.6
  • Composer
  • XDebug extension (disabled by default)

docker pull dalee/php-5.6

PHP 7.1

Image is squashed, so actually it contains only two layers.

  • PHP 7.1
  • Composer
  • XDebug extension (disabled by default)

docker pull dalee/php-7.1

PHP 7.2

Image is squashed, so actually it contains only two layers.

  • PHP 7.2
  • Composer
  • XDebug extension (disabled by default)

docker pull dalee/php-7.2

Releases

  • latest — latest master branch
  • vX.Y.Z — tagged release