105 lines
4.5 KiB
Docker
105 lines
4.5 KiB
Docker
# vim:set ft=dockerfile:
|
|
FROM debian:buster-slim
|
|
|
|
# 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
|
|
|
|
# https://bugs.debian.org/830696 (apt uses gpgv by default in newer releases, rather than gpg)
|
|
RUN set -ex; \
|
|
apt-get update; \
|
|
if ! which gpg; then \
|
|
apt-get install -y --no-install-recommends gnupg; \
|
|
fi; \
|
|
if ! gpg --version | grep -q '^gpg (GnuPG) 1\.'; then \
|
|
# Ubuntu includes "gnupg" (not "gnupg2", but still 2.x), but not dirmngr, and gnupg 2.x requires dirmngr
|
|
# so, if we're not running gnupg 1.x, explicitly install dirmngr too
|
|
apt-get install -y --no-install-recommends dirmngr; \
|
|
fi; \
|
|
rm -rf /var/lib/apt/lists/*;
|
|
|
|
# add gosu for easy step-down from root
|
|
# https://github.com/tianon/gosu/releases
|
|
ENV GOSU_VERSION 1.12
|
|
RUN set -eux; \
|
|
savedAptMark="$(apt-mark showmanual)"; \
|
|
apt-get update; \
|
|
apt-get install -y --no-install-recommends ca-certificates wget; \
|
|
rm -rf /var/lib/apt/lists/*; \
|
|
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
|
|
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
|
|
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
|
|
export GNUPGHOME="$(mktemp -d)"; \
|
|
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
|
|
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
|
|
gpgconf --kill all; \
|
|
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
|
|
apt-mark auto '.*' > /dev/null; \
|
|
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \
|
|
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
|
|
chmod +x /usr/local/bin/gosu; \
|
|
gosu --version; \
|
|
gosu nobody true
|
|
|
|
RUN mkdir /docker-entrypoint-initdb.d
|
|
|
|
# install "pwgen" for randomizing passwords
|
|
# install "tzdata" for /usr/share/zoneinfo/
|
|
# install "xz-utils" for .sql.xz docker-entrypoint-initdb.d files
|
|
RUN set -ex; \
|
|
apt-get update; \
|
|
apt-get install -y --no-install-recommends \
|
|
pwgen \
|
|
tzdata \
|
|
xz-utils \
|
|
; \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
# bashbrew-architectures: amd64 arm64v8 ppc64le
|
|
#ENV MARIADB_MAJOR 10.3
|
|
#ENV MARIADB_VERSION 1:10.3.22-0+deb10u1
|
|
# release-status:RC
|
|
# (https://downloads.mariadb.org/mariadb/+releases/)
|
|
|
|
# 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
|
|
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; \
|
|
apt-get install -y \
|
|
"mariadb-server" \
|
|
# mariadb-backup is installed at the same time so that `mysql-common` is only installed once from just mariadb repos
|
|
mariadb-backup \
|
|
socat \
|
|
; \
|
|
rm -rf /var/lib/apt/lists/*; \
|
|
# comment out any "user" entires in the MySQL config ("docker-entrypoint.sh" or "--user" will handle user switching)
|
|
sed -ri 's/^user\s/#&/' /etc/mysql/my.cnf /etc/mysql/conf.d/*; \
|
|
echo '[mysqld]\ninnodb_use_native_aio = 0\ninnodb_file_per_table = 1\n' >>/etc/mysql/conf.d/innodb_aio.cnf; \
|
|
# purge and re-create /var/lib/mysql with appropriate ownership
|
|
rm -rf /var/lib/mysql; \
|
|
mkdir -p /var/lib/mysql /var/run/mysqld; \
|
|
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld; \
|
|
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime
|
|
chmod 777 /var/run/mysqld; \
|
|
# comment out a few problematic configuration values
|
|
find /etc/mysql/ -name '*.cnf' -print0 \
|
|
| xargs -0 grep -lZE '^(bind-address|log)' \
|
|
| xargs -rt -0 sed -Ei 's/^(bind-address|log)/#&/'; \
|
|
# don't reverse lookup hostnames, they are usually another container
|
|
echo '[mysqld]\nskip-host-cache\nskip-name-resolve' > /etc/mysql/conf.d/docker.cnf; \
|
|
apt-get clean -y;
|
|
|
|
VOLUME /var/lib/mysql
|
|
|
|
COPY docker-entrypoint.sh /usr/local/bin/
|
|
|
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
|
EXPOSE 3306
|
|
CMD ["mysqld"]
|