|
| 1 | +# vim:set ft=dockerfile: |
| 2 | +FROM debian:buster |
| 3 | + |
| 4 | +# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added |
| 5 | +RUN groupadd -r mysql && useradd -r -g mysql mysql |
| 6 | + |
| 7 | +# https://bugs.debian.org/830696 (apt uses gpgv by default in newer releases, rather than gpg) |
| 8 | +RUN set -ex; \ |
| 9 | + apt-get update; \ |
| 10 | + if ! which gpg; then \ |
| 11 | + apt-get install -y --no-install-recommends gnupg; \ |
| 12 | + fi; \ |
| 13 | +# Ubuntu includes "gnupg" (not "gnupg2", but still 2.x), but not dirmngr, and gnupg 2.x requires dirmngr |
| 14 | +# so, if we're not running gnupg 1.x, explicitly install dirmngr too |
| 15 | + if ! gpg --version | grep -q '^gpg (GnuPG) 1\.'; then \ |
| 16 | + apt-get install -y --no-install-recommends dirmngr; \ |
| 17 | + fi; \ |
| 18 | + rm -rf /var/lib/apt/lists/* |
| 19 | + |
| 20 | +# add gosu for easy step-down from root |
| 21 | +ENV GOSU_VERSION 1.10 |
| 22 | +RUN set -ex; \ |
| 23 | + \ |
| 24 | + fetchDeps=' \ |
| 25 | + ca-certificates \ |
| 26 | + wget \ |
| 27 | + '; \ |
| 28 | + apt-get update; \ |
| 29 | + apt-get install -y --no-install-recommends $fetchDeps; \ |
| 30 | + rm -rf /var/lib/apt/lists/*; \ |
| 31 | + \ |
| 32 | + dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ |
| 33 | + wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \ |
| 34 | + wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \ |
| 35 | + \ |
| 36 | +# verify the signature |
| 37 | + export GNUPGHOME="$(mktemp -d)"; \ |
| 38 | + gpg --keyserver keyserver.ubuntu.com --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ |
| 39 | + gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ |
| 40 | + command -v gpgconf > /dev/null && gpgconf --kill all || :; \ |
| 41 | + rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc; \ |
| 42 | + \ |
| 43 | + chmod +x /usr/local/bin/gosu; \ |
| 44 | +# verify that the binary works |
| 45 | + gosu nobody true; \ |
| 46 | + \ |
| 47 | + apt-get purge -y --auto-remove $fetchDeps |
| 48 | + |
| 49 | +RUN mkdir /docker-entrypoint-initdb.d |
| 50 | + |
| 51 | +# install "pwgen" for randomizing passwords |
| 52 | +# install "tzdata" for /usr/share/zoneinfo/ |
| 53 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 54 | + apt-transport-https ca-certificates \ |
| 55 | + pwgen \ |
| 56 | + tzdata \ |
| 57 | + && rm -rf /var/lib/apt/lists/* |
| 58 | + |
| 59 | +ENV GPG_KEYS \ |
| 60 | +# Key fingerprint = 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB |
| 61 | +# MariaDB Package Signing Key <package-signing-key@mariadb.org> |
| 62 | +# for MariaDB 5.5 |
| 63 | + 199369E5404BD5FC7D2FE43BCBCB082A1BB943DB \ |
| 64 | +# pub rsa4096 2016-03-30 [SC] |
| 65 | +# 177F 4010 FE56 CA33 3630 0305 F165 6F24 C74C D1D8 |
| 66 | +# uid [ unknown] MariaDB Signing Key <signing-key@mariadb.org> |
| 67 | +# sub rsa4096 2016-03-30 [E] |
| 68 | +# for MariaDB 10+ |
| 69 | + 177F4010FE56CA3336300305F1656F24C74CD1D8 |
| 70 | + |
| 71 | +RUN set -ex; \ |
| 72 | + export GNUPGHOME="$(mktemp -d)"; \ |
| 73 | + for key in $GPG_KEYS; do \ |
| 74 | + gpg --keyserver keyserver.ubuntu.com --recv-keys "$key"; \ |
| 75 | + done; \ |
| 76 | + gpg --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mariadb.gpg; \ |
| 77 | + command -v gpgconf > /dev/null && gpgconf --kill all || :; \ |
| 78 | + rm -r "$GNUPGHOME"; \ |
| 79 | + apt-key list |
| 80 | + |
| 81 | +# bashbrew-architectures: amd64 arm64v8 ppc64le |
| 82 | +ENV MARIADB_MAJOR 10.4 |
| 83 | + |
| 84 | +RUN set -e;\ |
| 85 | + echo "deb http://downloads.mariadb.com/MariaDB/mariadb-$MARIADB_MAJOR/repo/debian buster main" > /etc/apt/sources.list.d/mariadb.list; \ |
| 86 | + { \ |
| 87 | + echo 'Package: *'; \ |
| 88 | + echo 'Pin: release o=MariaDB'; \ |
| 89 | + echo 'Pin-Priority: 999'; \ |
| 90 | + } > /etc/apt/preferences.d/mariadb |
| 91 | +# add repository pinning to make sure dependencies from this MariaDB repo are preferred over Debian dependencies |
| 92 | +# libmariadbclient18 : Depends: libmysqlclient18 (= 5.5.61+maria-1~wheezy) but 5.5.43-0+deb7u1 is to be installed |
| 93 | + |
| 94 | +# 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) |
| 95 | +# also, we set debconf keys to make APT a little quieter |
| 96 | +RUN set -ex; \ |
| 97 | + { \ |
| 98 | + echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password password 'unused'; \ |
| 99 | + echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password_again password 'unused'; \ |
| 100 | + } | debconf-set-selections; \ |
| 101 | + backupPackage='mariadb-backup'; \ |
| 102 | + apt-get update; \ |
| 103 | + apt-get install -y \ |
| 104 | + "mariadb-server" \ |
| 105 | + $backupPackage \ |
| 106 | + socat \ |
| 107 | + ; \ |
| 108 | + rm -rf /var/lib/apt/lists/*; \ |
| 109 | +# comment out any "user" entires in the MySQL config ("docker-entrypoint.sh" or "--user" will handle user switching) |
| 110 | + sed -ri 's/^user\s/#&/' /etc/mysql/my.cnf /etc/mysql/conf.d/*; \ |
| 111 | +# purge and re-create /var/lib/mysql with appropriate ownership |
| 112 | + rm -rf /var/lib/mysql; \ |
| 113 | + mkdir -p /var/lib/mysql /var/run/mysqld; \ |
| 114 | + chown -R mysql:mysql /var/lib/mysql /var/run/mysqld; \ |
| 115 | +# 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 |
| 116 | + chmod 777 /var/run/mysqld; \ |
| 117 | +# comment out a few problematic configuration values |
| 118 | + find /etc/mysql/ -name '*.cnf' -print0 \ |
| 119 | + | xargs -0 grep -lZE '^(bind-address|log)' \ |
| 120 | + | xargs -rt -0 sed -Ei 's/^(bind-address|log)/#&/'; \ |
| 121 | +# don't reverse lookup hostnames, they are usually another container |
| 122 | + echo '[mysqld]\nskip-host-cache\nskip-name-resolve' > /etc/mysql/conf.d/docker.cnf |
| 123 | + |
| 124 | +VOLUME /var/lib/mysql |
| 125 | + |
| 126 | +COPY docker-entrypoint.sh /usr/local/bin/ |
| 127 | +run chmod 755 /usr/local/bin/docker-entrypoint.sh |
| 128 | +RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat |
| 129 | +ENTRYPOINT ["/docker-entrypoint.sh"] |
| 130 | + |
| 131 | +EXPOSE 3306 |
| 132 | +CMD ["mysqld"] |
0 commit comments