alpine-influxdb
MultiArch Alpine Linux + S6 + InfluxDB
This image serves as the base image for applications / services that need a Influx (v1) database running.
Usually coupled with alpine-grafana image for the dashboard, and using telegraf or alpine-netdata to collect the metrics. (Enable the OpenTSDB listener for netdata and such.)
Based on Alpine Linux from the s6 image with the influxdb package installed in it.
InfluxDB Version 1.8.10
InfluxDB has since dropped providing binaries for ARM V7/V6, so packages are unavailable in Alpine Linux Repositories since v3.17
. This image uses the final pre-built packages from that repository. Newer builds will follow suit.
Get the Image¶
Pull the image from Docker Hub.
Image Tags
The image is tagged respectively for the following architectures,
latest tag is annotated as multiarch so pulling without any tags should fetch the correct image for your architecture. Same goes for any of the version tags.
non-x86_64 builds have embedded binfmt_misc support and contain the qemu-user-static binary that allows for running it also inside an x86_64 environment that has support for it.
Run¶
Running the container starts the service.
docker run --rm -it \
--name docker_influxdb \
-p 8086:8086 \
-p 8088:8088 \
-p 4242:4242 \
-v $PWD/data:/var/lib/influxdb \
woahbase/alpine-influxdb
Multi-Arch Support
If you want to run images for other architectures on a x86_64 machine, you will need to have binfmt support configured for your machine before running the image. multiarch, has made it easy for us containing that into a docker container, just run
Now images built for other architectures will also be executable. This is optional though, without the above, you can still run the image that is made for your architecture.
Configuration¶
We can customize the runtime behaviour of the container with the following environment variables.
ENV Vars | Default | Description |
---|---|---|
INFLUXDB_CONFIG_PATH | /etc/influxdb.conf | Default path to configuration file. |
INFLUXDB_HOME | /var/lib/influxdb | Default path to datastore. |
INFLUXDB_(var_name) | unset | Override default configurations. Check this link for supported variables. |
INFLUXDB_INIT_DB | /var/lib/influxdb/initdb.d | Directory for .sh or .iql scripts needed to initialize database. (Used by /scripts/run.sh ) |
INFLUXDB_BACKUPDIR | /var/lib/influxdb/backups | Directory for backups. (Used by /scripts/run.sh ) |
S6_NEEDED_PACKAGES | empty string | Space-separated list of extra APK packages to install on start. E.g. "curl git tzdata" |
PUID | 1000 | Id of S6_USER . |
PGID | 100 | Group id of S6_USER . |
S6_USER | alpine | (Preset) Default non-root user for services to drop privileges to. |
S6_USERHOME | /var/lib/influxdb | (Preset) HOME directory for S6_USER . |
Did you know?
You can check your own UID/GID by running the command id
in a terminal.
Also,
-
Configuration file is at
/etc/influxdb.conf
(the filepath preset in the env-varINFLUXDB_CONFIG_PATH
), edit or remount this with your own. A sample is provided in/defaults
, this gets copied when no such file exists before service is started. -
Default configuration starts the database server without any authorization. (Not recommended other than development or one-off testing purposes. Check the security guides for more)
-
To enable authentication/authorization, first update the configuration file or set
Any following executions will requireINFLUXDB_HTTP_AUTH_ENABLED
environment variable totrue
. Then create the administrator user with,-username
and-password
arguments set. E.g. for creating another non-root administrator (recommended to use/export these credentials as administrator, while keeping the above secret), -
For creating databases (and optionally limiting user-access specific to that database), execute the following as an example, check the docs for writing your own.
CREATE DATABASE "test"; -- following users operate ONLY on test-db -- test writer CREATE USER "testwriter" WITH PASSWORD 'insecurebydefaultwritetest'; REVOKE ALL PRIVILEGES FROM "testwriter"; GRANT WRITE ON "test" TO "testwriter"; -- test reader CREATE USER "testreader" WITH PASSWORD 'insecurebydefaultreadtest'; REVOKE ALL PRIVILEGES FROM "testreader"; GRANT READ ON "test" TO "testreader";
Script - run.sh¶
A script to run a few common tasks is available into the image,
-
If you already have customized scripts or
iql
files to initialize your database, mount them in/var/lib/influxdb/initdb.d
, and execute them via the script provided in/scripts/run.sh
. -
Backup a single database to
/var/lib/influxdb/backups
with -
Restore a single database from
/var/lib/influxdb/backups
with -
Optionally run a healthcheck query (if authentication is enabled, make sure to set either
The healthcheck query can be customized byINFLUXDB_HEALTHCHECK_USER
andINFLUXDB_HEALTHCHECK_USER_PWD
orINFLUXDB_USER
andINFLUXDB_USER_PWD
) withINFLUXDB_HEALTHCHECK_QUERY
environment variable (defaults toSHOW DATABASES
).
Stop the container with a timeout, (defaults to 2 seconds)
Restart the container with
Removes the container, (always better to stop it first and -f
only when needed most)
Shell access¶
Get a shell inside a already running container,
Optionally, login as a non-root user, (default is alpine
)
Or set user/group id e.g 1000/100,
Logs¶
To check logs of a running container in real time
As-A-Service¶
Run the container as a service with the following as reference (and modify it as needed).
With docker-compose (alpine-influxdb.yml)
---
services:
influxdb:
container_name: influxdb
deploy:
resources:
limits:
cpus: '4.00'
memory: 4096M
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 5
window: 120s
environment:
PUID: ${PUID:-1000}
PGID: ${PGID:-100}
# TZ: ${TZ}
INFLUXDB_REPORTING_DISABLED: true
# INFLUXDB_ADMIN_USER: ${INFLUXDB_ADMIN_USER:-admin}
# INFLUXDB_ADMIN_PWD: ${INFLUXDB_ADMIN_PWD:-admin}
# INFLUXDB_HEALTHCHECK_USER: ${INFLUXDB_HEALTHCHECK_USER:-hc}
# INFLUXDB_HEALTHCHECK_USER_PWD: ${INFLUXDB_HEALTHCHECK_PWD:-hc}
INFLUXDB_GRAPHITE_ENABLED: false
# healthcheck:
# interval: 2m
# retries: 5
# start_period: 5m
# test:
# - CMD-SHELL
# - >
# influx
# -username ${INFLUXDB_HEALTHCHECK_USER}
# -password ${INFLUXDB_HEALTHCHECK_USER_PWD}
# -execute 'SHOW DATABASES'
# || exit 1
# # curl -f http://localhost:8086/metrics
# timeout: 10s
hostname: influxdb
image: woahbase/alpine-influxdb:${INFLUXDB_TAG}
network_mode: bridge
ports:
- protocol: tcp
host_ip: 0.0.0.0
published: 8083
target: 8083
- protocol: tcp
host_ip: 0.0.0.0
published: 2003
target: 2003
- protocol: tcp
host_ip: 0.0.0.0
published: '${INFLUXDB_PORT:-8086}'
target: 8086
volumes:
- type: bind
source: ${INFLUXDB_DIR:?err}/data
target: /var/lib/influxdb
bind:
create_host_path: true
# - type: bind
# source: ${INFLUXDB_DIR:?err}/configs/influxdb.conf
# target: /etc/influxdb.conf
# bind:
# create_host_path: false
- type: bind
source: /etc/localtime
target: /etc/localtime
read_only: true
bind:
create_host_path: false
With HashiCorp Nomad (alpine-influxdb.hcl)
variables {
dc = "dc1" # to load the dc-local config file
pgid = 100 # gid for docker
puid = 1000 # uid for docker
version = "1.8.10"
}
# locals { var = yamldecode(file("${var.dc}.vars.yml")) } # load dc-local config file
job "influxdb" {
datacenters = [var.dc]
# namespace = local.var.namespace
priority = 80
# region = local.var.region
type = "service"
constraint { distinct_hosts = true }
# vault { policies = ["nomad-kv-readonly"] }
group "docker" {
count = 1
restart {
attempts = 2
interval = "2m"
delay = "15s"
mode = "fail"
}
update {
max_parallel = 1
min_healthy_time = "10s"
healthy_deadline = "10m"
progress_deadline = "15m"
auto_revert = false
}
service {
name = NOMAD_JOB_NAME
port = "http"
tags = ["ins${NOMAD_ALLOC_INDEX}", attr.unique.hostname, "aid=${NOMAD_ALLOC_ID}", "host=influxdb"]
canary_tags = ["canary${NOMAD_ALLOC_INDEX}"]
check {
name = "${NOMAD_JOB_NAME}@${attr.unique.hostname}:${NOMAD_HOST_PORT_http}"
type = "http"
path = "/health"
interval = "60s"
timeout = "10s"
}
check {
name = "ping-client"
command = "/bin/bash"
args = ["-c", "influx -username $INFLUXDB_HEALTHCHECK_USER -password $INFLUXDB_HEALTHCHECK_USER_PWD -execute 'SHOW DATABASES'"]
task = "influxdb"
type = "script"
interval = "60s"
timeout = "10s"
}
check_restart {
limit = 3
grace = "10m"
}
}
ephemeral_disk { size = 128 } # MB
network {
# dns { servers = local.var.dns_servers }
# port "admin" { static = 8083 } # deprecated
port "http" { static = 8086 }
port "rpc" { static = 8088 }
# port "udp" { static = 8089 }
# port "collectd" { static = 25826 }
port "graphite" { static = 2003 }
# port "otsdb" { static = 4242 }
}
volume "nomad-influxdb-data" {
type = "host"
read_only = false
source = "nomad-influxdb-data"
}
task "influxdb" {
driver = "docker"
config {
healthchecks { disable = true }
hostname = NOMAD_JOB_NAME
image = "woahbase/alpine-influxdb:${var.version}"
network_mode = "host"
ports = ["http", "rpc", "graphite"]
logging {
type = "journald"
config {
mode = "non-blocking"
tag = NOMAD_JOB_NAME
}
}
# mount {
# source = "local/influxdb.conf"
# target = "/etc/influxdb.conf"
# type = "bind"
# readonly = true
# }
mount {
type = "bind"
target = "/etc/localtime"
source = "/etc/localtime"
readonly = true
}
}
volume_mount {
# ensure policies allow vault-generated-token to read-write to the volume
volume = "nomad-influxdb-data"
destination = "/var/lib/influxdb"
read_only = false
}
env {
PUID = var.puid
PGID = var.pgid
# TZ = local.var.tz
INFLUXDB_REPORTING_DISABLED = "true"
INFLUXDB_GRAPHITE_ENABLED = "false"
}
resources {
cpu = 2000 # MHz
memory = 5120 # MB
}
# template {
# destination = "local/influxdb.conf"
# data = <<-EOC
# {{ key "nomad/${var.dc}/influxdb/influxdb.conf" }}
# EOC
# change_mode = "restart"
# perms = "644"
# error_on_missing_key = true
# }
template {
destination = "secrets/env"
data = <<-EOE
{{ with secret "kv/data/nomad/${var.dc}/influxdb" }}
INFLUXDB_HEALTHCHECK_USER={{ .Data.data.username }}
INFLUXDB_HEALTHCHECK_USER_PWD={{ .Data.data.password }}
{{ end }}
EOE
change_mode = "restart"
env = true
perms = "444"
error_on_missing_key = true
}
}
}
}
Reverse Proxy¶
To proxy it through a web server, see below
This snippet can be used to reverse-proxy the service using NGINX.
upstream proxy_influxdb {
server your.host.local:<influxdb-port> fail_timeout=5;
}
server {
server_name influxdb.local;
listen 443 ssl;
ssl_certificate /config/keys/certificate.crt;
ssl_certificate_key /config/keys/private.key;
# Recommendations from
# https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
# required to avoid HTTP 411: see Issue #1486 (https://github.com/moby/moby/issues/1486)
chunked_transfer_encoding on;
auth_basic off;
location / {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_pass_request_headers on;
proxy_http_version 1.1;
add_header Strict-Transport-Security "max-age=15552000";
proxy_set_header Connection "";
# proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://proxy_influxdb;
}
}
Build Your Own¶
Feel free to clone (or fork) the repository and customize it for your own usage, build the image for yourself on your own systems, and optionally, push it to your own public (or private) repository.
Here's how...
Setting up¶
Before we clone the /repository, we must have Git, GNU make, and Docker (optionally, with buildx plugin for multi-platform images) setup on the machine. Also, for multi-platform annotations, we might require enabling experimental features of Docker.
Now, to get the code,
Clone the repository with,
To get a list of all available targets, run
Always Check Before You Make!
Did you know, we could check what any make target is going to execute before we actually run them, with
Build and Test¶
To create the image for your architecture, run the build
and test
target with
For building an image that targets another architecture, it is required to specify the ARCH
parameter when building. e.g.
Build Parameters
All images have a few common build parameters that can be customized at build time, like
ARCH
- The target architecture to build for. Defaults to host architecture, auto-detected at build-time if not specified. Also determines if binfmt support is required before build or run and runs the
regbinfmt
target automatically. Possible values areaarch64
,armhf
,armv7l
, andx86_64
.
BUILDDATE
- The date of the build. Can be used to create separate tags for images. (format:
yyyymmdd
)
DOCKERFILE
- The dockerfile to use for build. Defaults to the file Dockerfile, but if per-arch dockerfiles exist, (e.g. for x86_64 the filename would be
Dockerfile_x86_64
) that is used instead.
TESTCMD
- The command to run for testing the image after build. Runs in a bash shell.
VERSION
- The version of the app/tool, may need to be preset before starting the build (e.g. for binaries from github releases), or extracted from the image after build (e.g. for APK or pip packages).
REGISTRY
- The registry to push to, defaults to the Docker Hub Registry (
docker.io
) or any custom registry that is set via docker configurations. Does not need to be changed for local or test builds, but to override, either pass it by setting an environment variable, or with everymake
command.
ORGNAME
- The organization (or user) name under which the image repositories exist, defaults to
woahbase
. Does not need to be changed for local or test builds, but to override, either pass it by setting an environment variable, or with everymake
command.
The image may also require custom parameters (like binary architecture). Before you build, check the makefile for a complete list of parameters to see what may (or may not) need to be set.
BuildX and Self-signed certificates
If you're using a private registry (a-la docker distribution server) with self-signed certificates, that fail to validate when pulling/pushing images. You will need to configure buildx to allow insecure access to the registry. This is configured via the config.toml
file. A sample is provided in the repository, make sure to replace YOUR.PRIVATE.REGISTRY
with your own (include port if needed).
Make to Run¶
Running the image creates a container and either starts a service (for service images) or provides a shell (can be either a root-shell or usershell) to execute commands in, depending on the image. We can run the image with
But if we just need a root-shell in the container without any fance pre-tasks (e.g. for debug or to test something bespoke), we can run bash
in the container with --entrypoint /bin/bash
. This is wrapped in the makefile as
Nothing vs All vs Run vs Shell
By default, if make
is run without any arguments, it calls the target all
. In our case this is usually mapped to the target run
(which in turn may be mapped to shell
).
There may be more such targets defined as per the usage of the image. Check the makefile for more information.
Push the Image¶
If the build and test steps finish without any error, and we want to use the image on other machines, it is the next step push the image we built to a container image repository (like /hub), for that, run the push
target with
If the built image targets another architecture then it is required to specify the ARCH
parameter when pushing. e.g.
Pushing Multiple Tags
With a single make push
, we are actually pushing 3 tags of the same image, e.g. for x86_64
architecture, they're namely
alpine-influxdb:x86_64
- The actual image that is built.
alpine-influxdb:x86_64_(version)
- It is expected that the application is versioned when built or packaged, it can be specified in the tag, this makes pulling an image by tag possible. Usually this is obtained from the parameter
VERSION
, which by default, is set by calling a function to extract the version string from the package installed in the container, or from github releases. Can be skipped with the parameterSKIP_VERSIONTAG
to a non-empty string value like1
.
alpine-influxdb:x86_64_(version)_(builddate)
- When building multiple versions of the same image (e.g. for providing fixes or revisions), this ensures that a more recent push does not fully replace a previously pushed image. This way, although the architecture and version tags are replaced, it is possible to roll back to the previously built image by build date (format
yyyymmdd
). This value is obtained from theBUILDDATE
parameter, and if not essential, can be skipped by setting the parameterSKIP_BUILDDATETAG
to a non-empty string value like1
.
Pushing To A Private Registry
If you want to push the image to a custom registry that is not pre-configured on your system, you can set the REGISTRY
variable either on the build environment, or as a makefile parameter, and that will be used instead of the default Docker Hub repository. Make sure to have push access set up before you actually push, and include port if needed. E.g.
or
Annotate Manifest(s)¶
For single architecture images, the above should suffice, the built image can be used in the host machine, and on other machines that have the same architecture too, i.e. after a push.
But for use-cases that need to support multiple architectures, there's a couple more things that need to be done. We need to create
(or amend
if already created beforehand) a manifest for the image(s) that we built, then annotate it to map the images to their respective architectures. And for our three tags created above we need to do it thrice.
Did you know?
We can inspect the manifest of any image by running
Tag Latest¶
Assuming we built the images for all supported architectures, to facilitate pulling the correct image for the architecture, we can create/amend the latest
manifest and annotate it to map the tags :aarch64
, :armhf
, :armv7l
, :x86_64
to the tag :latest
by running
How it works
First we create or amend the manifest with the tag latest
Then annotate the image for each architecture in the manifest with
And finally, push it to the repository using
Tag Version¶
Next, to facilitate pulling images by version, we create/amend the image-version manifest and annotate it to map the tags :aarch64_(version)
, :armhf_(version)
, :armv7l_(version)
, :x86_64_(version)
to the tag :(version)
by running
How it works
First we create or amend the manifest with the tag (version)
Then annotate the image for each architecture in the manifest with
And finally, push it to the repository using
Tag Build-Date¶
Then, (optionally) we create/amend the (version)_(builddate)
manifest and annotate it to map the tags :aarch64_(version)_(builddate)
, :armhf_(version)_(builddate)
, :armv7l_(version)_(builddate)
, :x86_64_(version)_(builddate)
to the tag :(version)_(builddate)
by running
How it works
First we create or amend the manifest with the tag (version)_(builddate)
docker manifest create --amend \
woahbase/alpine-influxdb:(version)_(builddate) \
woahbase/alpine-influxdb:aarch64_(version)_(builddate) \
woahbase/alpine-influxdb:armhf_(version)_(builddate) \
woahbase/alpine-influxdb:armv7l_(version)_(builddate) \
woahbase/alpine-influxdb:x86_64_(version)_(builddate) \
;
Then annotate the image for each architecture in the manifest with
And finally, push it to the repository using
That's all folks! Happy containerizing!
Maintenance¶
Sources at Github. Built and tested at home using Buildbot. Images at Docker Hub.
Maintained (or sometimes a lack thereof?) by WOAHBase.