Improve devcontainer Dockerfile following best practices

- Use apt-get instead of apt for better script compatibility
- Add --no-install-recommends to reduce image size
- Add cleanup to remove apt cache
- Parameterize external tool versions with build args
This commit is contained in:
toms74209200
2025-07-11 22:51:14 +09:00
parent 54a4ed0f5e
commit f91aed5440
2 changed files with 13 additions and 7 deletions

View File

@@ -4,7 +4,8 @@ ARG TZ
ENV TZ="$TZ" ENV TZ="$TZ"
# Install basic development tools and iptables/ipset # Install basic development tools and iptables/ipset
RUN apt update && apt install -y less \ RUN apt-get update && apt-get install -y --no-install-recommends \
less \
git \ git \
procps \ procps \
sudo \ sudo \
@@ -19,7 +20,8 @@ RUN apt update && apt install -y less \
iproute2 \ iproute2 \
dnsutils \ dnsutils \
aggregate \ aggregate \
jq jq \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Ensure default node user has access to /usr/local/share # Ensure default node user has access to /usr/local/share
RUN mkdir -p /usr/local/share/npm-global && \ RUN mkdir -p /usr/local/share/npm-global && \
@@ -42,10 +44,11 @@ RUN mkdir -p /workspace /home/node/.claude && \
WORKDIR /workspace WORKDIR /workspace
ARG GIT_DELTA_VERSION=0.18.2
RUN ARCH=$(dpkg --print-architecture) && \ RUN ARCH=$(dpkg --print-architecture) && \
wget "https://github.com/dandavison/delta/releases/download/0.18.2/git-delta_0.18.2_${ARCH}.deb" && \ wget "https://github.com/dandavison/delta/releases/download/${GIT_DELTA_VERSION}/git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" && \
sudo dpkg -i "git-delta_0.18.2_${ARCH}.deb" && \ sudo dpkg -i "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" && \
rm "git-delta_0.18.2_${ARCH}.deb" rm "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb"
# Set up non-root user # Set up non-root user
USER node USER node
@@ -58,7 +61,8 @@ ENV PATH=$PATH:/usr/local/share/npm-global/bin
ENV SHELL=/bin/zsh ENV SHELL=/bin/zsh
# Default powerline10k theme # Default powerline10k theme
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.2.0/zsh-in-docker.sh)" -- \ ARG ZSH_IN_DOCKER_VERSION=1.2.0
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v${ZSH_IN_DOCKER_VERSION}/zsh-in-docker.sh)" -- \
-p git \ -p git \
-p fzf \ -p fzf \
-a "source /usr/share/doc/fzf/examples/key-bindings.zsh" \ -a "source /usr/share/doc/fzf/examples/key-bindings.zsh" \

View File

@@ -3,7 +3,9 @@
"build": { "build": {
"dockerfile": "Dockerfile", "dockerfile": "Dockerfile",
"args": { "args": {
"TZ": "${localEnv:TZ:America/Los_Angeles}" "TZ": "${localEnv:TZ:America/Los_Angeles}",
"GIT_DELTA_VERSION": "0.18.2",
"ZSH_IN_DOCKER_VERSION": "1.2.0"
} }
}, },
"runArgs": [ "runArgs": [