@@ -4,11 +4,25 @@ FROM debian:%%SUITE%%
44# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
55RUN groupadd -r mysql && useradd -r -g mysql mysql
66
7- # install "pwgen" for randomizing passwords
8- RUN apt-get update && apt-get install -y pwgen && rm -rf /var/lib/apt/lists/*
7+ # add gosu for easy step-down from root
8+ ENV GOSU_VERSION 1.7
9+ RUN set -x \
10+ && apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
11+ && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
12+ && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
13+ && export GNUPGHOME="$(mktemp -d)" \
14+ && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
15+ && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
16+ && rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
17+ && chmod +x /usr/local/bin/gosu \
18+ && gosu nobody true \
19+ && apt-get purge -y --auto-remove ca-certificates wget
920
1021RUN mkdir /docker-entrypoint-initdb.d
1122
23+ # install "pwgen" for randomizing passwords
24+ RUN apt-get update && apt-get install -y pwgen && rm -rf /var/lib/apt/lists/*
25+
1226# Key fingerprint = 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB
1327# MariaDB Package Signing Key <[email protected] >1428# Key fingerprint = 430B DF5C 56E7 C94E 848E E60C 1C4C BDCD CD2E FD2A
@@ -48,8 +62,13 @@ RUN { \
4862 percona-xtrabackup \
4963 socat \
5064 && rm -rf /var/lib/apt/lists/* \
51- && rm -rf /var/lib/mysql \
52- && mkdir /var/lib/mysql
65+ # comment out any "user" entires in the MySQL config ("docker-entrypoint.sh" or "--user" will handle user switching)
66+ && sed -ri 's/^user\s /#&/' /etc/mysql/my.cnf /etc/mysql/conf.d/* \
67+ # purge and re-create /var/lib/mysql with appropriate ownership
68+ && rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \
69+ && chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \
70+ # 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
71+ && chmod 777 /var/run/mysqld
5372
5473# comment out a few problematic configuration values
5574# don't reverse lookup hostnames, they are usually another container
@@ -59,9 +78,9 @@ RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf \
5978
6079VOLUME /var/lib/mysql
6180
62- COPY docker-entrypoint.sh /
63-
64- ENTRYPOINT ["/ docker-entrypoint.sh" ]
81+ COPY docker-entrypoint.sh /usr/local/bin/
82+ RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
83+ ENTRYPOINT ["docker-entrypoint.sh" ]
6584
6685EXPOSE 3306
6786CMD ["mysqld" ]
0 commit comments