From 9c83dfd40b088c67eb37aa344410a0b23ca11ca1 Mon Sep 17 00:00:00 2001 From: Kinsue <1362567009.com> Date: Mon, 9 Mar 2026 11:45:59 +0100 Subject: [PATCH 1/2] chore: Optimize the Dockerfile to reduce the image size --- debian/Dockerfile | 29 ++++++++++++++--------------- redhat/Dockerfile | 35 ++++++++++++++++++----------------- ubuntu/Dockerfile | 28 ++++++++++++++-------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/debian/Dockerfile b/debian/Dockerfile index a90367ec..dd41d6e8 100644 --- a/debian/Dockerfile +++ b/debian/Dockerfile @@ -19,6 +19,8 @@ FROM debian:bookworm-slim ARG APISIX_VERSION=3.16.0 +COPY ./install-brotli.sh /install-brotli.sh + RUN set -ex; \ arch=$(dpkg --print-architecture); \ apt update; \ @@ -33,29 +35,26 @@ RUN set -ex; \ wget -O - https://repos.apiseven.com/pubkey.gpg | apt-key add - \ && echo "deb https://repos.apiseven.com/packages/arm64/debian debian12 main" | tee /etc/apt/sources.list.d/apisix.list \ ;; \ - esac; \ - apt update \ + esac \ + && apt update \ && apt install -y apisix=${APISIX_VERSION}-0 \ - && apt-get purge -y --auto-remove \ && rm /usr/local/openresty/bin/etcdctl \ && openresty -V \ - && apisix version - -COPY ./install-brotli.sh /install-brotli.sh -RUN chmod +x /install-brotli.sh \ - && cd / && ./install-brotli.sh && rm -rf /install-brotli.sh - -RUN apt-get -y purge --auto-remove curl wget gnupg --allow-remove-essential + && apisix version \ + && bash /install-brotli.sh \ + && rm -f /install-brotli.sh \ + && apt-get -y purge --auto-remove curl wget gnupg --allow-remove-essential \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && groupadd --system --gid 636 apisix \ + && useradd --system --gid apisix --no-create-home --shell /usr/sbin/nologin --uid 636 apisix \ + && chown -R apisix:0 /usr/local/apisix \ + && chmod -R g=u /usr/local/apisix WORKDIR /usr/local/apisix ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin -RUN groupadd --system --gid 636 apisix \ - && useradd --system --gid apisix --no-create-home --shell /usr/sbin/nologin --uid 636 apisix \ - && chown -R apisix:0 /usr/local/apisix \ - && chmod -R g=u /usr/local/apisix - USER apisix # forward request and error logs to docker log collector diff --git a/redhat/Dockerfile b/redhat/Dockerfile index 8469bd82..6aeb609f 100644 --- a/redhat/Dockerfile +++ b/redhat/Dockerfile @@ -19,33 +19,34 @@ FROM registry.access.redhat.com/ubi9/ubi:9.6 ARG APISIX_VERSION=3.16.0 LABEL apisix_version="${APISIX_VERSION}" + +WORKDIR /usr/local/apisix + COPY ./yum.repos.d/apache-apisix.repo /etc/yum.repos.d/apache-apisix.repo COPY ./yum.repos.d/openresty.repo /etc/yum.repos.d/openresty.repo +COPY ./install-brotli.sh /install-brotli.sh +COPY ./install-brotli.sh /install-brotli.sh RUN yum update -y \ && yum install -y apisix-${APISIX_VERSION} wget\ && yum clean all \ - && sed -i 's/PASS_MAX_DAYS\t99999/PASS_MAX_DAYS\t60/g' /etc/login.defs - -COPY ./install-brotli.sh /install-brotli.sh -RUN chmod +x /install-brotli.sh \ - && cd / && ./install-brotli.sh && rm -rf /install-brotli.sh + && sed -i 's/PASS_MAX_DAYS\t99999/PASS_MAX_DAYS\t60/g' /etc/login.defs \ + && chmod +x /install-brotli.sh \ + && cd / && ./install-brotli.sh && rm -rf /install-brotli.sh \ + && groupadd --system --gid 636 apisix \ + && useradd --system --gid apisix --no-create-home --shell /usr/sbin/nologin --uid 636 apisix \ + && chown -R apisix:0 /usr/local/apisix \ + && chmod -R g=u /usr/local/apisix \ + # forward request and error logs to docker log collector + && ln -sf /dev/stdout /usr/local/apisix/logs/access.log \ + && ln -sf /dev/stderr /usr/local/apisix/logs/error.log \ + && rm /usr/local/openresty/bin/etcdctl -WORKDIR /usr/local/apisix +USER apisix ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin -RUN groupadd --system --gid 636 apisix \ - && useradd --system --gid apisix --no-create-home --shell /usr/sbin/nologin --uid 636 apisix \ - && chown -R apisix:0 /usr/local/apisix \ - && chmod -R g=u /usr/local/apisix - -# forward request and error logs to docker log collector -RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \ - && ln -sf /dev/stderr /usr/local/apisix/logs/error.log \ - && rm /usr/local/openresty/bin/etcdctl - -USER apisix +WORKDIR /usr/local/apisix EXPOSE 9080 9443 diff --git a/ubuntu/Dockerfile b/ubuntu/Dockerfile index 6b85a632..8d8658a6 100644 --- a/ubuntu/Dockerfile +++ b/ubuntu/Dockerfile @@ -19,6 +19,10 @@ FROM ubuntu:24.04 ARG APISIX_VERSION=3.16.0 +COPY ./install-brotli.sh /install-brotli.sh + +WORKDIR /usr/local/apisix + RUN set -ex; \ arch=$(dpkg --print-architecture); \ apt update; \ @@ -36,26 +40,22 @@ RUN set -ex; \ esac; \ apt update \ && apt install -y apisix=${APISIX_VERSION}-0 \ - && apt-get purge -y --auto-remove \ && rm /usr/local/openresty/bin/etcdctl \ && openresty -V \ - && apisix version - -COPY ./install-brotli.sh /install-brotli.sh -RUN chmod +x /install-brotli.sh \ - && cd / && ./install-brotli.sh && rm -rf /install-brotli.sh - -RUN apt-get -y purge --auto-remove curl wget gnupg --allow-remove-essential - -WORKDIR /usr/local/apisix - -ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin - -RUN groupadd --system --gid 636 apisix \ + && apisix version \ + && bash /install-brotli.sh \ + && rm -f /install-brotli.sh \ + && apt-get -y purge --auto-remove curl wget gnupg --allow-remove-essential \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && groupadd --system --gid 636 apisix \ && useradd --system --gid apisix --no-create-home --shell /usr/sbin/nologin --uid 636 apisix \ && chown -R apisix:0 /usr/local/apisix \ && chmod -R g=u /usr/local/apisix + +ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin + USER apisix # forward request and error logs to docker log collector From 2e375c915767166e2ba7ea586e4278d8568b4dc9 Mon Sep 17 00:00:00 2001 From: Kinsue <1362567009.com> Date: Mon, 9 Mar 2026 16:32:38 +0100 Subject: [PATCH 2/2] Remove unnecessary cache and doc files in RedHat image --- redhat/Dockerfile | 13 +++++++++---- ubuntu/Dockerfile | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/redhat/Dockerfile b/redhat/Dockerfile index 6aeb609f..e4ba7d98 100644 --- a/redhat/Dockerfile +++ b/redhat/Dockerfile @@ -27,9 +27,12 @@ COPY ./yum.repos.d/openresty.repo /etc/yum.repos.d/openresty.repo COPY ./install-brotli.sh /install-brotli.sh COPY ./install-brotli.sh /install-brotli.sh -RUN yum update -y \ - && yum install -y apisix-${APISIX_VERSION} wget\ - && yum clean all \ +RUN set -ex; \ + yum makecache -y \ + && yum install -y \ + --setopt=install_weak_deps=False \ + --setopt=tsflags=nodocs \ + apisix-${APISIX_VERSION} wget\ && sed -i 's/PASS_MAX_DAYS\t99999/PASS_MAX_DAYS\t60/g' /etc/login.defs \ && chmod +x /install-brotli.sh \ && cd / && ./install-brotli.sh && rm -rf /install-brotli.sh \ @@ -40,7 +43,9 @@ RUN yum update -y \ # forward request and error logs to docker log collector && ln -sf /dev/stdout /usr/local/apisix/logs/access.log \ && ln -sf /dev/stderr /usr/local/apisix/logs/error.log \ - && rm /usr/local/openresty/bin/etcdctl + && rm /usr/local/openresty/bin/etcdctl \ + && yum clean all \ + && rm -rf /var/cache/dnf /var/cache/yum /var/lib/dnf/history.* /tmp/* /var/tmp/* USER apisix diff --git a/ubuntu/Dockerfile b/ubuntu/Dockerfile index 8d8658a6..ed1d9169 100644 --- a/ubuntu/Dockerfile +++ b/ubuntu/Dockerfile @@ -37,8 +37,8 @@ RUN set -ex; \ wget -O - https://repos.apiseven.com/pubkey.gpg | apt-key add - \ && echo "deb https://repos.apiseven.com/packages/arm64/ubuntu $VERSION_CODENAME main" | tee /etc/apt/sources.list.d/apisix.list \ ;; \ - esac; \ - apt update \ + esac \ + && apt update \ && apt install -y apisix=${APISIX_VERSION}-0 \ && rm /usr/local/openresty/bin/etcdctl \ && openresty -V \