From a62cbf1b6172534fd2e1924466a2e571c178f335 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 | 27 +++++++++++++-------------- redhat/Dockerfile | 21 ++++++++++----------- ubuntu/Dockerfile | 26 +++++++++++++------------- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/debian/Dockerfile b/debian/Dockerfile index b1249033..554db9f5 100644 --- a/debian/Dockerfile +++ b/debian/Dockerfile @@ -19,6 +19,8 @@ FROM debian:bullseye-slim ARG APISIX_VERSION=3.15.0 +COPY ./install-brotli.sh /install-brotli.sh + RUN set -ex; \ arch=$(dpkg --print-architecture); \ apt update; \ @@ -33,28 +35,25 @@ RUN set -ex; \ wget -O - https://repos.apiseven.com/pubkey.gpg | apt-key add - \ && echo "deb https://repos.apiseven.com/packages/arm64/debian $codename 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:apisix /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:apisix /usr/local/apisix - USER apisix # forward request and error logs to docker log collector diff --git a/redhat/Dockerfile b/redhat/Dockerfile index ab3213ba..e93bb3c7 100644 --- a/redhat/Dockerfile +++ b/redhat/Dockerfile @@ -19,27 +19,26 @@ FROM registry.access.redhat.com/ubi9/ubi:9.6 ARG APISIX_VERSION=3.15.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 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 - -WORKDIR /usr/local/apisix - -ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin - + && 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 \ # forward request and error logs to docker log collector -RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \ + && 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 +ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin + EXPOSE 9080 9443 COPY ./docker-entrypoint.sh /docker-entrypoint.sh diff --git a/ubuntu/Dockerfile b/ubuntu/Dockerfile index 2cc911db..63411fca 100644 --- a/ubuntu/Dockerfile +++ b/ubuntu/Dockerfile @@ -19,6 +19,10 @@ FROM ubuntu:24.04 ARG APISIX_VERSION=3.15.0 +COPY ./install-brotli.sh /install-brotli.sh + +WORKDIR /usr/local/apisix + RUN set -ex; \ arch=$(dpkg --print-architecture); \ apt update; \ @@ -36,25 +40,21 @@ 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 + && 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:apisix /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:apisix /usr/local/apisix - USER apisix # forward request and error logs to docker log collector From e8203da7905a26a1afdc8408aa49971e27593f46 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 | 19 ++++++++++++------- ubuntu/Dockerfile | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/redhat/Dockerfile b/redhat/Dockerfile index e93bb3c7..4a6edd6b 100644 --- a/redhat/Dockerfile +++ b/redhat/Dockerfile @@ -26,16 +26,21 @@ 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 -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 \ + && cd / && bash /install-brotli.sh \ + && rm -rf /install-brotli.sh \ # 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 + && ln -sf /dev/stderr /usr/local/apisix/logs/error.log \ + && rm /usr/local/openresty/bin/etcdctl \ + && yum clean all \ + && rm -rf /var/cache/dnf /var/cache/yum /var/lib/dnf/history.* /tmp/* /var/tmp/* ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin diff --git a/ubuntu/Dockerfile b/ubuntu/Dockerfile index 63411fca..40c7c833 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 \