mariadb-docker/Dockerfile.template

145 lines
6.6 KiB
Docker
Raw Normal View History

# vim:set ft=dockerfile:
FROM ubuntu:%%SUITE%%
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mysql && useradd -r -g mysql mysql --home-dir /var/lib/mysql && userdel --remove ubuntu
2016-05-17 12:48:56 -07:00
# add gosu for easy step-down from root
2020-04-16 00:06:26 -07:00
# https://github.com/tianon/gosu/releases
# gosu key is B42F6819007F00F88E364FD4036A9C25BF357DD4
2023-11-15 10:22:08 +11:00
ENV GOSU_VERSION 1.17
ARG GPG_KEYS=177F4010FE56CA3336300305F1656F24C74CD1D8
# pub rsa4096 2016-03-30 [SC]
# 177F 4010 FE56 CA33 3630 0305 F165 6F24 C74C D1D8
# uid [ unknown] MariaDB Signing Key <signing-key@mariadb.org>
# sub rsa4096 2016-03-30 [E]
# install "libjemalloc2" as it offers better performance in some cases. Use with LD_PRELOAD
# install "pwgen" for randomizing passwords
# install "tzdata" for /usr/share/zoneinfo/
# install "xz-utils" for .sql.xz docker-entrypoint-initdb.d files
# install "zstd" for .sql.zst docker-entrypoint-initdb.d files
# hadolint ignore=SC2086
2020-04-16 00:06:26 -07:00
RUN set -eux; \
2017-11-13 15:55:56 -08:00
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates \
gpg \
gpgv \
libjemalloc2 \
pwgen \
tzdata \
xz-utils \
zstd ; \
savedAptMark="$(apt-mark showmanual)"; \
apt-get install -y --no-install-recommends \
dirmngr \
gpg-agent \
wget; \
2017-11-13 15:55:56 -08:00
rm -rf /var/lib/apt/lists/*; \
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -q -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
wget -q -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
GNUPGHOME="$(mktemp -d)"; \
export GNUPGHOME; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
for key in $GPG_KEYS; do \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
done; \
gpg --batch --export "$GPG_KEYS" > /etc/apt/trusted.gpg.d/mariadb.gpg; \
if command -v gpgconf >/dev/null; then \
gpgconf --kill all; \
fi; \
2017-11-13 15:55:56 -08:00
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
2020-04-16 00:06:26 -07:00
gpgconf --kill all; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
apt-mark auto '.*' > /dev/null; \
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark >/dev/null; \
2020-04-16 00:06:26 -07:00
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
2017-11-13 15:55:56 -08:00
chmod +x /usr/local/bin/gosu; \
2020-04-16 00:06:26 -07:00
gosu --version; \
gosu nobody true
RUN mkdir /docker-entrypoint-initdb.d
# Ensure the container exec commands handle range of utf8 characters based of
# default locales in base image (https://github.com/docker-library/docs/blob/135b79cc8093ab02e55debb61fdb079ab2dbce87/ubuntu/README.md#locales)
ENV LANG C.UTF-8
2022-10-14 14:49:01 +11:00
# OCI annotations to image
LABEL org.opencontainers.image.authors="MariaDB Community" \
org.opencontainers.image.title="MariaDB Database" \
org.opencontainers.image.description="MariaDB Database for relational SQL" \
org.opencontainers.image.documentation="https://hub.docker.com/_/mariadb/" \
org.opencontainers.image.base.name="docker.io/library/ubuntu:%%SUITE%%" \
org.opencontainers.image.licenses="GPL-2.0" \
org.opencontainers.image.source="https://github.com/MariaDB/mariadb-docker" \
org.opencontainers.image.vendor="MariaDB Community" \
org.opencontainers.image.version="%%MARIADB_VERSION_BASIC%%" \
org.opencontainers.image.url="https://github.com/MariaDB/mariadb-docker"
# bashbrew-architectures:%%ARCHES%%
ARG MARIADB_MAJOR=%%MARIADB_MAJOR%%
ENV MARIADB_MAJOR $MARIADB_MAJOR
ARG MARIADB_VERSION=%%MARIADB_VERSION%%
ENV MARIADB_VERSION $MARIADB_VERSION
# release-status:%%MARIADB_RELEASE_STATUS%%
2023-05-08 11:59:02 +10:00
# release-support-type:%%MARIADB_SUPPORT_TYPE%%
# (https://downloads.mariadb.org/rest-api/mariadb/)
# Allowing overriding of REPOSITORY, a URL that includes suite and component for testing and Enterprise Versions
ARG REPOSITORY="http://archive.mariadb.org/mariadb-%%MARIADB_VERSION_BASIC%%/repo/ubuntu/ %%SUITE%% main main/debug"
RUN set -e;\
echo "deb ${REPOSITORY}" > /etc/apt/sources.list.d/mariadb.list; \
{ \
echo 'Package: *'; \
echo 'Pin: release o=MariaDB'; \
echo 'Pin-Priority: 999'; \
} > /etc/apt/preferences.d/mariadb
# add repository pinning to make sure dependencies from this MariaDB repo are preferred over Debian dependencies
# libmariadbclient18 : Depends: libmysqlclient18 (= 5.5.42+maria-1~wheezy) but 5.5.43-0+deb7u1 is to be installed
# the "/var/lib/mysql" stuff here is because the mysql-server postinst doesn't have an explicit way to disable the mysql_install_db codepath besides having a database already "configured" (ie, stuff in /var/lib/mysql/mysql)
# also, we set debconf keys to make APT a little quieter
# hadolint ignore=DL3015
RUN set -ex; \
{ \
echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password password 'unused'; \
echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password_again password 'unused'; \
} | debconf-set-selections; \
apt-get update; \
# postinst script creates a datadir, so avoid creating it by faking its existance.
mkdir -p /var/lib/mysql/mysql ; touch /var/lib/mysql/mysql/user.frm ; \
# mariadb-backup is installed at the same time so that `mysql-common` is only installed once from just mariadb repos
apt-get install -y --no-install-recommends mariadb-server="$MARIADB_VERSION" mariadb-backup socat \
; \
rm -rf /var/lib/apt/lists/*; \
2016-05-17 12:48:56 -07:00
# purge and re-create /var/lib/mysql with appropriate ownership
rm -rf /var/lib/mysql /etc/mysql/mariadb.conf.d/50-mysqld_safe.cnf; \
mkdir -p /var/lib/mysql /run/mysqld; \
chown -R mysql:mysql /var/lib/mysql /run/mysqld; \
# ensure that /run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime
chmod 1777 /run/mysqld; \
# comment out a few problematic configuration values
find /etc/mysql/ -name '*.cnf' -print0 \
2020-06-24 10:15:02 -07:00
| xargs -0 grep -lZE '^(bind-address|log|user\s)' \
| xargs -rt -0 sed -Ei 's/^(bind-address|log|user\s)/#&/'; \
# don't reverse lookup hostnames, they are usually another container
printf "[mariadb]\nhost-cache-size=0\nskip-name-resolve\n" > /etc/mysql/mariadb.conf.d/05-skipcache.cnf; \
/etc/mysql/conf.d for configuration files Per documentation /etc/mysql/conf.d is meant as a location for configuration to be mounted. In 10.5, my fault, /etc/mysql/mariadb.conf.d was read after /etc/mysql/conf.d and more harmfully with a number of configuration items there in /etc/mysql/mariadb.conf.d/50-server.cnf that can no-longer be overwritten in a standard way. Thanks to @tomzu in #327 we just read /etc/mysql/mariadb.conf.d before /etc/mysql/conf.d/ and existing behaviour is preserved. To ensure that /etc/mysql/conf.d can be mounted the "skip-host-cache", "skip-name-resolve" are no longer in /etc/mysql/conf.d/docker.cnf but in the /etc/mysql/my.cnf (or mariadb.cnf (10.5+)). [mariadb] is used as the group, but for 10.4+ [mariadbd] is also recognised. The state of the files across versions is as follows hence ensuring that [mariadbd] is used in later versions. A test case ensures this too: $ for v in 10.* ; do echo version=$v ; podman exec -ti mnew$v ls -lad /etc/mysql/my.cnf /etc/mysql/mariadb.cnf /etc/alternatives/my.cnf ; done version=10.2 ls: cannot access '/etc/mysql/mariadb.cnf': No such file or directory ls: cannot access '/etc/alternatives/my.cnf': No such file or directory -rw-r--r--. 1 root root 5189 Jun 9 09:45 /etc/mysql/my.cnf version=10.3 ls: cannot access '/etc/alternatives/my.cnf': No such file or directory -rw-r--r--. 1 root root 527 May 5 15:26 /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 5221 Jun 9 09:46 /etc/mysql/my.cnf version=10.4 ls: cannot access '/etc/alternatives/my.cnf': No such file or directory -rw-r--r--. 1 root root 527 May 5 20:10 /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 5221 Jun 9 09:45 /etc/mysql/my.cnf version=10.5 lrwxrwxrwx. 1 root root 22 Jun 9 09:42 /etc/alternatives/my.cnf -> /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 1172 Jun 9 09:42 /etc/mysql/mariadb.cnf lrwxrwxrwx. 1 root root 24 Jun 9 09:42 /etc/mysql/my.cnf -> /etc/alternatives/my.cnf version=10.6 lrwxrwxrwx. 1 root root 22 Jun 9 09:47 /etc/alternatives/my.cnf -> /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 1172 Jun 9 09:47 /etc/mysql/mariadb.cnf lrwxrwxrwx. 1 root root 24 Jun 9 09:47 /etc/mysql/my.cnf -> /etc/alternatives/my.cnf
2021-06-09 19:54:42 +10:00
# Issue #327 Correct order of reading directories /etc/mysql/mariadb.conf.d before /etc/mysql/conf.d (mount-point per documentation)
if [ -L /etc/mysql/my.cnf ]; then \
/etc/mysql/conf.d for configuration files Per documentation /etc/mysql/conf.d is meant as a location for configuration to be mounted. In 10.5, my fault, /etc/mysql/mariadb.conf.d was read after /etc/mysql/conf.d and more harmfully with a number of configuration items there in /etc/mysql/mariadb.conf.d/50-server.cnf that can no-longer be overwritten in a standard way. Thanks to @tomzu in #327 we just read /etc/mysql/mariadb.conf.d before /etc/mysql/conf.d/ and existing behaviour is preserved. To ensure that /etc/mysql/conf.d can be mounted the "skip-host-cache", "skip-name-resolve" are no longer in /etc/mysql/conf.d/docker.cnf but in the /etc/mysql/my.cnf (or mariadb.cnf (10.5+)). [mariadb] is used as the group, but for 10.4+ [mariadbd] is also recognised. The state of the files across versions is as follows hence ensuring that [mariadbd] is used in later versions. A test case ensures this too: $ for v in 10.* ; do echo version=$v ; podman exec -ti mnew$v ls -lad /etc/mysql/my.cnf /etc/mysql/mariadb.cnf /etc/alternatives/my.cnf ; done version=10.2 ls: cannot access '/etc/mysql/mariadb.cnf': No such file or directory ls: cannot access '/etc/alternatives/my.cnf': No such file or directory -rw-r--r--. 1 root root 5189 Jun 9 09:45 /etc/mysql/my.cnf version=10.3 ls: cannot access '/etc/alternatives/my.cnf': No such file or directory -rw-r--r--. 1 root root 527 May 5 15:26 /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 5221 Jun 9 09:46 /etc/mysql/my.cnf version=10.4 ls: cannot access '/etc/alternatives/my.cnf': No such file or directory -rw-r--r--. 1 root root 527 May 5 20:10 /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 5221 Jun 9 09:45 /etc/mysql/my.cnf version=10.5 lrwxrwxrwx. 1 root root 22 Jun 9 09:42 /etc/alternatives/my.cnf -> /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 1172 Jun 9 09:42 /etc/mysql/mariadb.cnf lrwxrwxrwx. 1 root root 24 Jun 9 09:42 /etc/mysql/my.cnf -> /etc/alternatives/my.cnf version=10.6 lrwxrwxrwx. 1 root root 22 Jun 9 09:47 /etc/alternatives/my.cnf -> /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 1172 Jun 9 09:47 /etc/mysql/mariadb.cnf lrwxrwxrwx. 1 root root 24 Jun 9 09:47 /etc/mysql/my.cnf -> /etc/alternatives/my.cnf
2021-06-09 19:54:42 +10:00
# 10.5+
sed -i -e '/includedir/ {N;s/\(.*\)\n\(.*\)/\n\2\n\1/}' /etc/mysql/mariadb.cnf; \
fi
/etc/mysql/conf.d for configuration files Per documentation /etc/mysql/conf.d is meant as a location for configuration to be mounted. In 10.5, my fault, /etc/mysql/mariadb.conf.d was read after /etc/mysql/conf.d and more harmfully with a number of configuration items there in /etc/mysql/mariadb.conf.d/50-server.cnf that can no-longer be overwritten in a standard way. Thanks to @tomzu in #327 we just read /etc/mysql/mariadb.conf.d before /etc/mysql/conf.d/ and existing behaviour is preserved. To ensure that /etc/mysql/conf.d can be mounted the "skip-host-cache", "skip-name-resolve" are no longer in /etc/mysql/conf.d/docker.cnf but in the /etc/mysql/my.cnf (or mariadb.cnf (10.5+)). [mariadb] is used as the group, but for 10.4+ [mariadbd] is also recognised. The state of the files across versions is as follows hence ensuring that [mariadbd] is used in later versions. A test case ensures this too: $ for v in 10.* ; do echo version=$v ; podman exec -ti mnew$v ls -lad /etc/mysql/my.cnf /etc/mysql/mariadb.cnf /etc/alternatives/my.cnf ; done version=10.2 ls: cannot access '/etc/mysql/mariadb.cnf': No such file or directory ls: cannot access '/etc/alternatives/my.cnf': No such file or directory -rw-r--r--. 1 root root 5189 Jun 9 09:45 /etc/mysql/my.cnf version=10.3 ls: cannot access '/etc/alternatives/my.cnf': No such file or directory -rw-r--r--. 1 root root 527 May 5 15:26 /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 5221 Jun 9 09:46 /etc/mysql/my.cnf version=10.4 ls: cannot access '/etc/alternatives/my.cnf': No such file or directory -rw-r--r--. 1 root root 527 May 5 20:10 /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 5221 Jun 9 09:45 /etc/mysql/my.cnf version=10.5 lrwxrwxrwx. 1 root root 22 Jun 9 09:42 /etc/alternatives/my.cnf -> /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 1172 Jun 9 09:42 /etc/mysql/mariadb.cnf lrwxrwxrwx. 1 root root 24 Jun 9 09:42 /etc/mysql/my.cnf -> /etc/alternatives/my.cnf version=10.6 lrwxrwxrwx. 1 root root 22 Jun 9 09:47 /etc/alternatives/my.cnf -> /etc/mysql/mariadb.cnf -rw-r--r--. 1 root root 1172 Jun 9 09:47 /etc/mysql/mariadb.cnf lrwxrwxrwx. 1 root root 24 Jun 9 09:47 /etc/mysql/my.cnf -> /etc/alternatives/my.cnf
2021-06-09 19:54:42 +10:00
VOLUME /var/lib/mysql
COPY healthcheck.sh /usr/local/bin/healthcheck.sh
2016-05-17 12:48:56 -07:00
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 3306
CMD ["mariadbd"]