Skip to content

SwagDevOps/image-alpine_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alpine Server Image

Image based on alpine:3.10.3 (release notes).

This image SHOULD consume less than 6MB RAM on startup (depending on RAM installed).

rake restart && \
sleep 6 && \
docker ps | awk '{print $1}' | grep -v CONTAINER | while read line; do docker ps | grep $line | awk '{printf $NF" "}' && echo "scale=2; $(cat /sys/fs/cgroup/memory/docker/$line*/memory.usage_in_bytes)/1024/1024" | bc -l; done | sort | column -t

For an image size around 56MB.

Why?

A complete init process

This image brings a 3 parts init system, composed of:

  1. ylem startup scripts execution
  2. dumb-init minimal init system for Linux containers
  3. runit services management

It would solve the PID 1 problem.

What's inside the image?

Component Comment
Alpine Linux Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.
ylem Startup scripts execution.
dumb-init A minimal init system for Linux containers.
runit Used as a service supervisor. Supports restarting daemons when they crash. See: runsvdir.
su-exec Execute a program with different privileges. The program will be executed directly and not run as a child, like su and sudo does, which avoids TTY and signal issues (see README). It is only 10kb.
sv-utils sv-utils is an attempt to bring DRY principle to runit services creation.
syslog Only listens locally. All syslog messages are forwarded to docker logs.
dropbear Dropbear is a relatively small SSH server. It has a small memory footprint and is compatible with OpenSSH ~/.ssh/authorized_keys public key authentication.
crond Comes with a cron system by default, provided by busybox.

Try

From sources

git clone git@github.com:SwagDevOps/image-alpine_server.git
cd image-alpine_server
bundle install --path vendor/bundle --without development
bundle exec rake build start exec

From docker hub

docker run -d --rm --name trying.alpine_server swagdevops/alpine_server:VERSION
docker exec -ti trying.alpine_server bash -l

Run tests

mkdir -p ssh/authorized_keys
cp ~/.ssh/id_rsa.pub ssh/authorized_keys/root
bundle exec rake restart test

Tests are executed over SSH, and rely on minimal (host) dependencies.

Using as base image

Getting started

The image is called swagdevops/alpine_server, and is available on the Docker registry.

Use swagdevops/alpine_server as base image.

FROM swagdevops/alpine_server:VERSION

To make your builds reproducible, you MUST lock down to a specific version, DO NOT use latest. ATM, latest tag does not exist, as a result: you CAN NOT use it.

See releases for a list of version numbers.

Adding additional daemons

A daemon is a program which runs in the background of its system, such as a web server.

You can add additional daemons (for example, your own app) to the image by creating runit service directories. You only have to write a small script to start your daemon. runsv will execute your script, and (by default) restart it upon its exit, after waiting one second.

The shell script must be called run, executable, and placed in the directory /etc/services/<NAME>. Additionally, a file manifest.yml must be present, with the following content:

---
enabled: true
auto_start: true

runsv will invoke run after your container starts.

Example for a run script

#!/usr/bin/env svrun
# vim: ai ts=2 sts=2 et sw=2 ft=ruby

Dir.chdir('/var/www/localhost') do
  service(['bundle',
           'exec',
           'rake',
           'serve',
           'serve_port=80',
           "serve_storage=/var/serve"],
          user: :'www-data',
          group: 'www-data').call
end

Filesystem hierarchy

/etc/services
└── httpd
    ├── manifest.yml
    └── run

For more information see: sv-utils.

See also