From b6e3f3f8dd8f82bbf94084895076bb0df2603aaf Mon Sep 17 00:00:00 2001 From: Mahesh Rijal <62394512+maheshrijal@users.noreply.github.com> Date: Thu, 17 Apr 2025 19:42:14 +0530 Subject: [PATCH] chore: reduce docker image size (#194) This PR makes changes in the Dockerfile to reduce the final image size. I'm sure this can be optimized further. But I didn't want to make too many changes at once. Original: ``` REPOSITORY TAG IMAGE ID CREATED SIZE codex latest c8f66942ded3 4 minutes ago 1.91GB ``` Now: ``` REPOSITORY TAG IMAGE ID CREATED SIZE codex latest 2a6d6450609c 4 minutes ago 747MB ``` --- codex-cli/Dockerfile | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/codex-cli/Dockerfile b/codex-cli/Dockerfile index 95fe3800..5f894203 100644 --- a/codex-cli/Dockerfile +++ b/codex-cli/Dockerfile @@ -1,11 +1,13 @@ -FROM node:20 +FROM node:20-slim ARG TZ ENV TZ="$TZ" -# Install basic development tools and iptables/ipset -RUN apt update && apt install -y \ +# Install basic development tools, ca-certificates, and iptables/ipset, then clean up apt cache to reduce image size +RUN apt-get update && apt-get install -y --no-install-recommends \ aggregate \ + ca-certificates \ + curl \ dnsutils \ fzf \ gh \ @@ -21,7 +23,8 @@ RUN apt update && apt install -y \ sudo \ unzip \ ripgrep \ - zsh + zsh \ + && rm -rf /var/lib/apt/lists/* # Ensure default node user has access to /usr/local/share RUN mkdir -p /usr/local/share/npm-global && \ @@ -38,7 +41,11 @@ ENV PATH=$PATH:/usr/local/share/npm-global/bin # Install codex COPY dist/codex.tgz codex.tgz -RUN npm install -g codex.tgz +RUN npm install -g codex.tgz \ + && npm cache clean --force \ + && rm -rf /usr/local/share/npm-global/lib/node_modules/codex-cli/node_modules/.cache \ + && rm -rf /usr/local/share/npm-global/lib/node_modules/codex-cli/tests \ + && rm -rf /usr/local/share/npm-global/lib/node_modules/codex-cli/docs # Copy and set up firewall script COPY scripts/init_firewall.sh /usr/local/bin/