Code Monkey home page Code Monkey logo

docker-alpine-micro's Introduction

microcontainer based on Alpine with working init process

This is a very small container (total 7.7 Mb) but still have a working init process, crond, syslog and logrotate. This is the base image for all my other microcontainers

Why use this image

The unix process ID 1 is the process to receive the SIGTERM signal when you execute a

docker stop <container ID>

if the container has the command CMD ["bash"] then bash process will get the SIGTERM signal and terminate. All other processes running on the system will just stop without the possibility to shutdown correclty

runit init process

In this container runit is used to handle starting and shuttning down processes automatically started

Adding your own startscript inside a container

Add a directory under the directory /etc/service/ that matches the process that should be started. Lets add a nginx start script to the container. First create the directory

mkdir /etc/service/nginx

and then create a file named run i that directory with the start code fpr nginx

#!/bin/sh
exec 2>&1
exec /usr/sbin/nginx -c /etc/nginx/nginx.conf  -g "daemon off;"

and make the file executable

chmod +x /etc/service/nginx/run

that command will be started automatically when the container is started. Be sure to start the command with flags that keeps it in the foreground otherwise runit will think that the process has ended and try to restart it.

Adding it to the Dockerfile

The above example is done in a Dockerfile by creating a file i the same directory as the Dockerfile as nginx.sh containing the code

#!/bin/sh
exec 2>&1
exec /usr/sbin/nginx -c /etc/nginx/nginx.conf  -g "daemon off;"

and make the file executable

chmod +x nginx.sh

and add this lines to Dockerfile

ADD nginx.sh /etc/service/nginx/run

Environment variables in start script

If you need environment variables from the docker command line (-e,--env=[]) add

source /etc/envvars

before you use them in the script file

In this container i have a scipt that handles the init process an uses the supervisor system to start the daemons to run and also catch signals (SIGTERM) to shutdown all processes started by supervisord. This is a modified version of an init script made by Phusion. I've modified it to use supervisor in stead of runit. There are also two directories to run scripts before any daemon is started.

Run script once /etc/runonce

All executable in this directory is run at start, after completion the script is removed from the directory

Run script every start /etc/runalways

All executable in this directory is run at every start of the container, ie, at docker run and docker start

Permanent output to docker log when starting container

Each time the container is started the content of the file /tmp/startup.log is displayed so if your startup scripts generate vital information to be shown please add that information to that file. This information can be retrieved anytime by executing docker logs <container id>

cron daemon

In many cases there are som need of things happening att given intervalls, default no cron processs is started in standard images. In this image cron is running together with logrotate to stop the logdfiles to be to big on log running containers.

rsyslogd

No all services works without a syslog daemon, if you don't have one running those messages is lost in space, all messages sent via the syslog daemon is saved in /var/log/syslog

Docker fixes

Also there are fixed (besideds the init process) assosiated with running linux inside a docker container.

Installation

This continer should normaly run as a daemon i.e with the -d flag attached

docker run -d nimmis/alpine-micro

Accessing the container with a shell can be done with

docker exec -ti <container ID> /bin/sh

This is the commands used inside nimmis/alpine based containers for extra functionality

set_tz

In the default configuration Alpine is set to GMT time, if you need it to use the corret time you can change to timezone for the container with this command, syntax is

set_tz <timezone>

To get list of available timezones do

set_tz list
set timezone on startup

Add the environment variable TIMEZONE to the desired timezone, i.e to set timezone to CET Stockhome

docker run -d -e TIMEZONE=Europa/Stockholm nimmis/alpine-micro
set timezone in running container

Execute the command on the container as

docker exec -ti <docker ID> set_tz Europa/Stockholm
get list of timezones before starting container

Execute the following command, it will list available timezones and then remove the container

docker run --rm nimmis/alpine-micro set_tz list

Issues

If you have any problems with or questions about this image, please contact us by submitting a ticket through a GitHub issue

  1. Look to see if someone already filled the bug, if not add a new one.
  2. Add a good title and description with the following information.
  • if possible an copy of the output from cat /etc/BUILDS/* from inside the container
  • any logs relevant for the problem
  • how the container was started (flags, environment variables, mounted volumes etc)
  • any other information that can be helpful

Contributing

You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.

TAGs

This image only contains the latest versions of Apline, the versions are nimmis/alpine-micro: where tag is

Tag Alpine version size
latest latest/3.5
3.5 3.5
3.4 3.4
3.3 3.3
3.2 3.2
3.1 3.1
edge edge

docker-alpine-micro's People

Contributors

nimmis avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.