Build your own s6-overlay base image

󰃭 2024-08-19

S6-overlay is a container-focused process manager that offers end-to-end management of the container’s lifecycle, from initialization to graceful shutdown.

To make use of s6-overlay we need to add the binaries to our container by adding, extracting and then moving them to the directory where they are expected.

ADD https://github.com/just-containers/s6-overlay/releases/download/3.2.0.0/s6-overlay-noarch.tar.xz /tmp  
ADD https://github.com/just-containers/s6-overlay/releases/download/3.2.0.0/s6-overlay-x86_64.tar.xz /tmp

Update dependencies

When adding the s6-overlay sources to in a Dockerfile we want to make sure that we get notified when a new version is available, so we can always be up-to-date with all our libraries. This can be achieved by adding a section to our Renovate or Dependabot config, a rule to match

Version checker know about Docker FROM

If we leverage the FROM of docker to include our sources we would not need to add anything. I already use the way of loading sources via images in several places:

include composer

FROM composer:2.7.7 AS composer
COPY --from=composer /usr/bin/composer /usr/bin/composer

include extension-installer

FROM mlocati/php-extension-installer:2.2.16 AS php-extension-installer
COPY --from=php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions \
  xdebug \
  zip \
;

But there is no base image for s6-overlay from justcontainers/s6-overlay . There are some other vendors, but they are opinionated and do more things that are helpful to their case.

Build your own s6-overlay base image

FROM alpine:3 AS s6

ARG TARGETARCH
ARG TARGETVARIANT
ARG S6_RELEASE

RUN apk add --no-cache curl jq \
    && if [ -z ${S6_RELEASE} ]; then \
         S6_RELEASE=$(curl -s https://api.github.com/repos/just-containers/s6-overlay/releases/latest | jq -r '.tag_name' | cut -c2-); \
       fi \
    && S6_PLATFORM=$(case "${TARGETARCH}/${TARGETVARIANT}" in \
         "arm/v7")   echo "armhf";; \
         "arm64/")   echo "aarch64";; \
         *)          echo "x86_64";; \
       esac) \
    && echo "Using s6 release ${S6_RELEASE} platform ${S6_PLATFORM}" \
    && curl -sSL "https://github.com/just-containers/s6-overlay/releases/download/v${S6_RELEASE}/s6-overlay-noarch.tar.xz" -o "/tmp/s6-overlay-noarch.tar.xz" \
    && curl -sSL "https://github.com/just-containers/s6-overlay/releases/download/v${S6_RELEASE}/s6-overlay-${S6_PLATFORM}.tar.xz" -o "/tmp/s6-overlay-${S6_PLATFORM}.tar.xz" \
    && curl -sSL "https://github.com/just-containers/s6-overlay/releases/download/v${S6_RELEASE}/s6-overlay-noarch.tar.xz.sha256" -o "/tmp/s6-overlay-noarch.tar.xz.sha256" \
    && curl -sSL "https://github.com/just-containers/s6-overlay/releases/download/v${S6_RELEASE}/s6-overlay-${S6_PLATFORM}.tar.xz.sha256" -o "/tmp/s6-overlay-${S6_PLATFORM}.tar.xz.sha256" \
    && cd /tmp \
    && sha256sum -c s6-overlay-noarch.tar.xz.sha256 \
    && sha256sum -c s6-overlay-${S6_PLATFORM}.tar.xz.sha256 \
    && mkdir -p /s6/root \
    && tar -C /s6/root -Jxpf /tmp/s6-overlay-noarch.tar.xz \
    && tar -C /s6/root -Jxpf /tmp/s6-overlay-${S6_PLATFORM}.tar.xz

FROM scratch
COPY --from=s6 /s6/root /s6/root

It

  • downloads for the specified architecture
  • asserts the checksum!
  • uses a fresh layer to copy everything

This can be built with:

docker build --no-cache --build-arg S6_RELEASE=3.2.0.0 -t hakindazz/s6-overlay-base:3.2.0.0 .

Or you can pull the image to check it out:

docker pull hakindazz/s6-overlay-base:3.2.0.0

Include via docker FROM

The best part: You can now include the versioned sources via docker --from:

FROM hakindazz/s6-overlay-base AS s6-overlay
FROM alpine3

COPY --from=s6-overlay /s6/root /

ENTRYPOINT ["/init"]

Happy image building!!!

Some sources:

Enter your instance's address


More posts like this

Mastering Multi-Process Containers: Running PHP Applications with s6-overlay

󰃭 2025-03-26 | #ci #devops #docker #s6-overlay

The Dockerized Development Setup

Containerization has completely changed how we build and deploy PHP applications. With Docker, you can make sure that your production environment behaves just like your local setup, which means fewer surprises when you go live.

In this post, we’re diving into running Symfony in a container that runs multiple processes using s6-overlay. We’ll explain why having more than one process in a container can be important, how this idea is different from Docker’s usual “one process per container” rule, and how s6-overlay makes it easier to run everything together.

Continue reading 


Manage s6-overlay setup with s6-cli

󰃭 2024-12-06 | #ci #devops #docker #s6-overlay

I developed a small cli in golang to ease creating, validating and documenting services that s6 supervises.

Usage

You do not need to install anything, just execute the binary via docker

docker run -it --rm hakindazz/s6-cli help
COMMANDS:
   create, c   create a service
   remove, rm  remove a service
   lint, l     lint directories and files
   mermaid, m  document s6 service dependencies in mermaid syntax
   help, h     Shows a list of commands or help for one command

Create a service with s6-cli

docker run -it --rm -v ./:/etc/s6-overlay hakindazz/s6-cli create oneshot init-dependencies

Here is the file / directory structure it creates:

Continue reading 