1. 获取构建mysql镜像的脚本
git clone https://github.com/docker-library/mysql.git
2.预先下载 gosu-arm64、gosu-arm64.asc ,并放到mysql/8.0目录下
wget -c https://github.com/tianon/gosu/releases/download/1.14/gosu-arm64
wget -c https://github.com/tianon/gosu/releases/download/1.14/gosu-arm64.asc
3.修改Dockerfile.oracle,使用本地下载的gosu
1 # 2 # NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" 3 # 4 # PLEASE DO NOT EDIT IT DIRECTLY. 5 # 6 7 FROM oraclelinux:8-slim 8 9 RUN set -eux; \ 10 groupadd --system --gid 999 mysql; \ 11 useradd --system --uid 999 --gid 999 --home-dir /var/lib/mysql --no-create-home mysql; \ 12 \ 13 mkdir /var/lib/mysql /var/run/mysqld; \ 14 chown mysql:mysql /var/lib/mysql /var/run/mysqld; \ 15 # 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 16 chmod 1777 /var/lib/mysql /var/run/mysqld; \ 17 \ 18 mkdir /docker-entrypoint-initdb.d 19 20 # add gosu for easy step-down from root 21 # https://github.com/tianon/gosu/releases 22 ENV GOSU_VERSION 1.14 23 COPY ./gosu-arm64 /usr/local/bin/gosu 24 COPY ./gosu-arm64.asc /usr/local/bin/gosu.asc 25 RUN set -eux; \ 26 # TODO find a better userspace architecture detection method than querying the kernel 27 arch="$(uname -m)"; \ 28 case "$arch" in \ 29 aarch64) gosuArch='arm64' ;; \ 30 x86_64) gosuArch='amd64' ;; \ 31 *) echo >&2 "error: unsupported architecture: '$arch'"; exit 1 ;; \ 32 esac; \ 33 # curl -fL -o /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$gosuArch.asc"; \ 34 # curl -fL -o /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$gosuArch"; \ 35 export GNUPGHOME="$(mktemp -d)"; \ 36 gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ 37 # gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ 38 rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \ 39 chmod +x /usr/local/bin/gosu; \ 40 gosu --version; \ 41 gosu nobody true 42 43 RUN set -eux; \ 44 microdnf install -y \ 45 gzip \ 46 openssl \ 47 xz \ 48 zstd \ 49 # Oracle Linux 8+ is very slim :) 50 findutils \ 51 ; \ 52 microdnf clean all 53 54 RUN set -eux; \ 55 # https://dev.mysql.com/doc/refman/8.0/en/checking-gpg-signature.html 56 # gpg: key 3A79BD29: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported 57 key='859BE8D7C586F538430B19C2467B942D3A79BD29'; \ 58 export GNUPGHOME="$(mktemp -d)"; \ 59 gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \ 60 gpg --batch --export --armor "$key" > /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql; \ 61 rm -rf "$GNUPGHOME" 62 63 ENV MYSQL_MAJOR 8.0 64 ENV MYSQL_VERSION 8.0.28-1.el8 65 66 RUN set -eu; \ 67 . /etc/os-release; \ 68 { \ 69 echo '[mysql8.0-server-minimal]'; \ 70 echo 'name=MySQL 8.0 Server Minimal'; \ 71 echo 'enabled=1'; \ 72 echo "baseurl=https://repo.mysql.com/yum/mysql-8.0-community/docker/el/${VERSION_ID%%[.-]*}/\$basearch/"; \ 73 echo 'gpgcheck=1'; \ 74 echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql'; \ 75 # https://github.com/docker-library/mysql/pull/680#issuecomment-825930524 76 echo 'module_hotfixes=true'; \ 77 } | tee /etc/yum.repos.d/mysql-community-minimal.repo 78 79 RUN set -eux; \ 80 microdnf install -y "mysql-community-server-minimal-$MYSQL_VERSION"; \ 81 microdnf clean all; \ 82 # the "socket" value in the Oracle packages is set to "/var/lib/mysql" which isn't a great place for the socket (we want it in "/var/run/mysqld" instead) 83 # https://github.com/docker-library/mysql/pull/680#issuecomment-636121520 84 grep -F 'socket=/var/lib/mysql/mysql.sock' /etc/my.cnf; \ 85 sed -i 's!^socket=.*!socket=/var/run/mysqld/mysqld.sock!' /etc/my.cnf; \ 86 grep -F 'socket=/var/run/mysqld/mysqld.sock' /etc/my.cnf; \ 87 { echo '[client]'; echo 'socket=/var/run/mysqld/mysqld.sock'; } >> /etc/my.cnf; \ 88 \ 89 # make sure users dumping files in "/etc/mysql/conf.d" still works 90 ! grep -F '!includedir' /etc/my.cnf; \ 91 { echo; echo '!includedir /etc/mysql/conf.d/'; } >> /etc/my.cnf; \ 92 mkdir -p /etc/mysql/conf.d; \ 93 \ 94 mysqld --version; \ 95 mysql --version 96 97 RUN set -eu; \ 98 . /etc/os-release; \ 99 { \ 100 echo '[mysql-tools-community]'; \ 101 echo 'name=MySQL Tools Community'; \ 102 echo "baseurl=https://repo.mysql.com/yum/mysql-tools-community/el/${VERSION_ID%%[.-]*}/\$basearch/"; \ 103 echo 'enabled=1'; \ 104 echo 'gpgcheck=1'; \ 105 echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql'; \ 106 # https://github.com/docker-library/mysql/pull/680#issuecomment-825930524 107 echo 'module_hotfixes=true'; \ 108 } | tee /etc/yum.repos.d/mysql-community-tools.repo 109 ENV MYSQL_SHELL_VERSION 8.0.28-1.el8 110 RUN set -eux; \ 111 microdnf install -y "mysql-shell-$MYSQL_SHELL_VERSION"; \ 112 microdnf clean all; \ 113 \ 114 mysqlsh --version 115 116 VOLUME /var/lib/mysql 117 118 COPY docker-entrypoint.sh /usr/local/bin/ 119 ENTRYPOINT ["docker-entrypoint.sh"] 120 121 EXPOSE 3306 33060 122 CMD ["mysqld"]
4.执行构建Docker镜像
1 [uos@localhost 8.0]$ docker build -f ./Dockerfile.oracle -t arm64uos/oracle-mysql:8.0 . 2 Sending build context to Docker daemon 2.265MB 3 Step 1/20 : FROM oraclelinux:8-slim 4 8-slim: Pulling from library/oraclelinux 5 293fbd461d2c: Pull complete 6 Digest: sha256:d36eb5962270036295bc6c9409a191abe8d9683be5641d20d124df52c5abb587 7 Status: Downloaded newer image for oraclelinux:8-slim 8 ---> 7f0650a84bb9 9 Step 2/20 : RUN set -eux; groupadd --system --gid 999 mysql; useradd --system --uid 999 --gid 999 --home-dir /var/lib/mysql --no-create-home mysql; mkdir /var/lib/mysql /var/run/mysqld; chown mysql:mysql /var/lib/mysql /var/run/mysqld; chmod 1777 /var/lib/mysql /var/run/mysqld; mkdir /docker-entrypoint-initdb.d 10 ---> Running in a96e89974f96 11 + groupadd --system --gid 999 mysql 12 + useradd --system --uid 999 --gid 999 --home-dir /var/lib/mysql --no-create-home mysql 13 + mkdir /var/lib/mysql /var/run/mysqld 14 + chown mysql:mysql /var/lib/mysql /var/run/mysqld 15 + chmod 1777 /var/lib/mysql /var/run/mysqld 16 + mkdir /docker-entrypoint-initdb.d 17 Removing intermediate container a96e89974f96 18 ---> aaaa3a268e6a 19 Step 3/20 : ENV GOSU_VERSION 1.14 20 ---> Running in dee510f38ad9 21 Removing intermediate container dee510f38ad9 22 ---> 61b74ea8e658 23 Step 4/20 : COPY ./gosu-arm64 /usr/local/bin/gosu 24 ---> f573051a6ef2 25 Step 5/20 : COPY ./gosu-arm64.asc /usr/local/bin/gosu.asc 26 ---> 14a1cd823dc6 27 Step 6/20 : RUN set -eux; arch="$(uname -m)"; case "$arch" in aarch64) gosuArch='arm64' ;; x86_64) gosuArch='amd64' ;; *) echo >&2 "error: unsupported architecture: '$arch'"; exit 1 ;; esac; export GNUPGHOME="$(mktemp -d)"; gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; chmod +x /usr/local/bin/gosu; gosu --version; gosu nobody true 28 ---> Running in 7a2def91005f 29 ++ uname -m 30 + arch=aarch64 31 + case "$arch" in 32 + gosuArch=arm64 33 ++ mktemp -d 34 + export GNUPGHOME=/tmp/tmp.C3hcKppY6K 35 + GNUPGHOME=/tmp/tmp.C3hcKppY6K 36 + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 37 gpg: keybox '/tmp/tmp.C3hcKppY6K/pubring.kbx' created 38 gpg: /tmp/tmp.C3hcKppY6K/trustdb.gpg: trustdb created 39 gpg: key 036A9C25BF357DD4: public key "Tianon Gravi <tianon@tianon.xyz>" imported 40 gpg: Total number processed: 1 41 gpg: imported: 1 42 + rm -rf /tmp/tmp.C3hcKppY6K /usr/local/bin/gosu.asc 43 + chmod +x /usr/local/bin/gosu 44 + gosu --version 45 1.14 (go1.16.7 on linux/arm64; gc) 46 + gosu nobody true 47 Removing intermediate container 7a2def91005f 48 ---> 497704b804d2 49 Step 7/20 : RUN set -eux; microdnf install -y gzip openssl xz zstd findutils ; microdnf clean all 50 ---> Running in 05b43fc314d9 51 + microdnf install -y gzip openssl xz zstd findutils 52 Downloading metadata... 53 Downloading metadata... 54 Package Repository Size 55 Installing: 56 findutils-1:4.6.0-20.el8.aarch64 ol8_baseos_latest 537.4 kB 57 gzip-1.9-12.el8.aarch64 ol8_baseos_latest 168.3 kB 58 openssl-1:1.1.1k-6.el8_5.aarch64 ol8_baseos_latest 706.2 kB 59 xz-5.2.4-3.el8.aarch64 ol8_baseos_latest 156.1 kB 60 zstd-1.4.4-1.0.1.el8.aarch64 ol8_appstream 310.0 kB 61 Transaction Summary: 62 Installing: 5 packages 63 Reinstalling: 0 packages 64 Upgrading: 0 packages 65 Obsoleting: 0 packages 66 Removing: 0 packages 67 Downgrading: 0 packages 68 Downloading packages... 69 Running transaction test... 70 Installing: zstd;1.4.4-1.0.1.el8;aarch64;ol8_appstream 71 Installing: xz;5.2.4-3.el8;aarch64;ol8_baseos_latest 72 Installing: openssl;1:1.1.1k-6.el8_5;aarch64;ol8_baseos_latest 73 Installing: gzip;1.9-12.el8;aarch64;ol8_baseos_latest 74 Installing: findutils;1:4.6.0-20.el8;aarch64;ol8_baseos_latest 75 Complete. 76 + microdnf clean all 77 Complete. 78 Removing intermediate container 05b43fc314d9 79 ---> 198bc6b97443 80 Step 8/20 : RUN set -eux; key='859BE8D7C586F538430B19C2467B942D3A79BD29'; export GNUPGHOME="$(mktemp -d)"; gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; gpg --batch --export --armor "$key" > /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql; rm -rf "$GNUPGHOME" 81 ---> Running in e0272592ac40 82 + key=859BE8D7C586F538430B19C2467B942D3A79BD29 83 ++ mktemp -d 84 + export GNUPGHOME=/tmp/tmp.de2UOzFBxB 85 + GNUPGHOME=/tmp/tmp.de2UOzFBxB 86 + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys 859BE8D7C586F538430B19C2467B942D3A79BD29 87 gpg: keybox '/tmp/tmp.de2UOzFBxB/pubring.kbx' created 88 gpg: /tmp/tmp.de2UOzFBxB/trustdb.gpg: trustdb created 89 gpg: key 467B942D3A79BD29: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported 90 gpg: Total number processed: 1 91 gpg: imported: 1 92 + gpg --batch --export --armor 859BE8D7C586F538430B19C2467B942D3A79BD29 93 + rm -rf /tmp/tmp.de2UOzFBxB 94 Removing intermediate container e0272592ac40 95 ---> 3bf34d537ce4 96 Step 9/20 : ENV MYSQL_MAJOR 8.0 97 ---> Running in f74c1276a825 98 Removing intermediate container f74c1276a825 99 ---> 71115750eae1 100 Step 10/20 : ENV MYSQL_VERSION 8.0.28-1.el8 101 ---> Running in add5007830f4 102 Removing intermediate container add5007830f4 103 ---> 329e98f9e6ea 104 Step 11/20 : RUN set -eu; . /etc/os-release; { echo '[mysql8.0-server-minimal]'; echo 'name=MySQL 8.0 Server Minimal'; echo 'enabled=1'; echo "baseurl=https://repo.mysql.com/yum/mysql-8.0-community/docker/el/${VERSION_ID%%[.-]*}/\$basearch/"; echo 'gpgcheck=1'; echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql'; echo 'module_hotfixes=true'; } | tee /etc/yum.repos.d/mysql-community-minimal.repo 105 ---> Running in 098701a53769 106 [mysql8.0-server-minimal] 107 name=MySQL 8.0 Server Minimal 108 enabled=1 109 baseurl=https://repo.mysql.com/yum/mysql-8.0-community/docker/el/8/$basearch/ 110 gpgcheck=1 111 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 112 module_hotfixes=true 113 Removing intermediate container 098701a53769 114 ---> 81e9656252a7 115 Step 12/20 : RUN set -eux; microdnf install -y "mysql-community-server-minimal-$MYSQL_VERSION"; microdnf clean all; grep -F 'socket=/var/lib/mysql/mysql.sock' /etc/my.cnf; sed -i 's!^socket=.*!socket=/var/run/mysqld/mysqld.sock!' /etc/my.cnf; grep -F 'socket=/var/run/mysqld/mysqld.sock' /etc/my.cnf; { echo '[client]'; echo 'socket=/var/run/mysqld/mysqld.sock'; } >> /etc/my.cnf; ! grep -F '!includedir' /etc/my.cnf; { echo; echo '!includedir /etc/mysql/conf.d/'; } >> /etc/my.cnf; mkdir -p /etc/mysql/conf.d; mysqld --version; mysql --version 116 ---> Running in 5024aade5e13 117 + microdnf install -y mysql-community-server-minimal-8.0.28-1.el8 118 Downloading metadata... 119 Downloading metadata... 120 Downloading metadata... 121 Package Repository Size 122 Installing: 123 libaio-0.3.112-1.el8.aarch64 ol8_baseos_latest 33.2 kB 124 libtirpc-1.1.4-5.0.1.el8.aarch64 ol8_baseos_latest 111.5 kB 125 mysql-community-server-minimal-8.0.28-1.el8.aarch64 mysql8.0-server-minimal 33.3 MB 126 Transaction Summary: 127 Installing: 3 packages 128 Reinstalling: 0 packages 129 Upgrading: 0 packages 130 Obsoleting: 0 packages 131 Removing: 0 packages 132 Downgrading: 0 packages 133 Downloading packages... 134 Running transaction test... 135 Installing: libtirpc;1.1.4-5.0.1.el8;aarch64;ol8_baseos_latest 136 Installing: libaio;0.3.112-1.el8;aarch64;ol8_baseos_latest 137 Installing: mysql-community-server-minimal;8.0.28-1.el8;aarch64;mysql8.0-server-minimal 138 Complete. 139 + microdnf clean all 140 Complete. 141 + grep -F socket=/var/lib/mysql/mysql.sock /etc/my.cnf 142 socket=/var/lib/mysql/mysql.sock 143 + sed -i 's!^socket=.*!socket=/var/run/mysqld/mysqld.sock!' /etc/my.cnf 144 + grep -F socket=/var/run/mysqld/mysqld.sock /etc/my.cnf 145 socket=/var/run/mysqld/mysqld.sock 146 + echo '[client]' 147 + echo socket=/var/run/mysqld/mysqld.sock 148 + grep -F '!includedir' /etc/my.cnf 149 + echo 150 + echo '!includedir /etc/mysql/conf.d/' 151 + mkdir -p /etc/mysql/conf.d 152 + mysqld --version 153 /usr/sbin/mysqld Ver 8.0.28 for Linux on aarch64 (MySQL Community Server - GPL) 154 + mysql --version 155 mysql Ver 8.0.28 for Linux on aarch64 (MySQL Community Server - GPL) 156 Removing intermediate container 5024aade5e13 157 ---> 75d6d11a0d4f 158 Step 13/20 : RUN set -eu; . /etc/os-release; { echo '[mysql-tools-community]'; echo 'name=MySQL Tools Community'; echo "baseurl=https://repo.mysql.com/yum/mysql-tools-community/el/${VERSION_ID%%[.-]*}/\$basearch/"; echo 'enabled=1'; echo 'gpgcheck=1'; echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql'; echo 'module_hotfixes=true'; } | tee /etc/yum.repos.d/mysql-community-tools.repo 159 ---> Running in 370f3e954c65 160 [mysql-tools-community] 161 name=MySQL Tools Community 162 baseurl=https://repo.mysql.com/yum/mysql-tools-community/el/8/$basearch/ 163 enabled=1 164 gpgcheck=1 165 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 166 module_hotfixes=true 167 Removing intermediate container 370f3e954c65 168 ---> 930aadf4bd26 169 Step 14/20 : ENV MYSQL_SHELL_VERSION 8.0.28-1.el8 170 ---> Running in 12cb073265f5 171 Removing intermediate container 12cb073265f5 172 ---> 146a70d69280 173 Step 15/20 : RUN set -eux; microdnf install -y "mysql-shell-$MYSQL_SHELL_VERSION"; microdnf clean all; mysqlsh --version 174 ---> Running in ded458b7a5c5 175 + microdnf install -y mysql-shell-8.0.28-1.el8 176 Downloading metadata... 177 Downloading metadata... 178 Downloading metadata... 179 Downloading metadata... 180 Package Repository Size 181 Installing: 182 expat-2.2.5-4.0.1.el8_5.3.aarch64 ol8_baseos_latest 105.8 kB 183 gdbm-libs-1:1.18-1.el8.aarch64 ol8_baseos_latest 60.5 kB 184 libnsl2-1.2.0-2.20180605git4a062cf.el8.aarch64 ol8_baseos_latest 56.4 kB 185 mysql-shell-8.0.28-1.el8.aarch64 mysql-tools-community 18.6 MB 186 python39-libs-3.9.6-2.module+el8.5.0+20364+c7fe1181.aarch64 ol8_appstream 8.4 MB 187 python39-pip-wheel-20.2.4-6.module+el8.5.0+20364+c7fe1181.noarch ol8_appstream 1.3 MB 188 python39-setuptools-wheel-50.3.2-4.module+el8.5.0+20364+c7fe1181.noarch ol8_appstream 508.6 kB 189 Transaction Summary: 190 Installing: 7 packages 191 Reinstalling: 0 packages 192 Upgrading: 0 packages 193 Obsoleting: 0 packages 194 Removing: 0 packages 195 Downgrading: 0 packages 196 Enabling module streams: 197 python39:3.9 198 199 200 Downloading packages... 201 Running transaction test... 202 Installing: python39-setuptools-wheel;50.3.2-4.module+el8.5.0+20364+c7fe1181;noarch;ol8_appstream 203 Installing: python39-pip-wheel;20.2.4-6.module+el8.5.0+20364+c7fe1181;noarch;ol8_appstream 204 Installing: libnsl2;1.2.0-2.20180605git4a062cf.el8;aarch64;ol8_baseos_latest 205 Installing: gdbm-libs;1:1.18-1.el8;aarch64;ol8_baseos_latest 206 Installing: expat;2.2.5-4.0.1.el8_5.3;aarch64;ol8_baseos_latest 207 Installing: python39-libs;3.9.6-2.module+el8.5.0+20364+c7fe1181;aarch64;ol8_appstream 208 Installing: mysql-shell;8.0.28-1.el8;aarch64;mysql-tools-community 209 Complete. 210 + microdnf clean all 211 Complete. 212 + mysqlsh --version 213 Cannot set LC_ALL to locale en_US.UTF-8: No such file or directory 214 mysqlsh Ver 8.0.28 for Linux on aarch64 - for MySQL 8.0.28 (MySQL Community Server (GPL)) 215 Removing intermediate container ded458b7a5c5 216 ---> 242cc65de9a1 217 Step 16/20 : VOLUME /var/lib/mysql 218 ---> Running in 5cc99dcada97 219 Removing intermediate container 5cc99dcada97 220 ---> fd89b8c734f5 221 Step 17/20 : COPY docker-entrypoint.sh /usr/local/bin/ 222 ---> 2793d27294e2 223 Step 18/20 : ENTRYPOINT ["docker-entrypoint.sh"] 224 ---> Running in 057accf923c3 225 Removing intermediate container 057accf923c3 226 ---> 39b58c0645c2 227 Step 19/20 : EXPOSE 3306 33060 228 ---> Running in e08e5b46adfc 229 Removing intermediate container e08e5b46adfc 230 ---> eed18bbc8cbd 231 Step 20/20 : CMD ["mysqld"] 232 ---> Running in a356b9dc7916 233 Removing intermediate container a356b9dc7916 234 ---> df723596f0a2 235 Successfully built df723596f0a2 236 Successfully tagged arm64uos/oracle-mysql:8.0docker build