From 105b7dfc1c40427c400468cfc8c1cbba49ae9573 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Wed, 30 Apr 2025 06:55:34 +0800 Subject: [PATCH] Simplify and unify apk usage in Dockerfiles (#3407) Replace `apk update` and `--update` flags with `--no-cache` across Dockerfiles to improve consistency and eliminate unnecessary cache files. This change reduces image size and ensures up-to-date package indices without leaving temporary data. It also aligns with best practices recommended for Alpine-based Docker images. --- Dockerfile | 2 +- Dockerfile-quick | 2 +- docker/Dockerfile-go-builder | 2 +- docker/Dockerfile-netclient-multiarch | 2 +- docker/Dockerfile-netclient-multiarch-userspace | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 13652393..950c48b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ FROM alpine:3.21.3 # add a c lib # set the working directory WORKDIR /root/ -RUN apk update && apk upgrade +RUN apk upgrade --no-cache RUN apk add --no-cache sqlite RUN mkdir -p /etc/netclient/config COPY --from=builder /app/netmaker . diff --git a/Dockerfile-quick b/Dockerfile-quick index f4b3eee9..f7cda278 100644 --- a/Dockerfile-quick +++ b/Dockerfile-quick @@ -6,7 +6,7 @@ COPY ./netmaker /root/netmaker ENV GO111MODULE=auto # add a c lib -RUN apk add gcompat iptables wireguard-tools +RUN apk add --no-cache gcompat iptables wireguard-tools # set the working directory WORKDIR /root/ RUN mkdir -p /etc/netclient/config diff --git a/docker/Dockerfile-go-builder b/docker/Dockerfile-go-builder index 982f1e6f..90f9a810 100644 --- a/docker/Dockerfile-go-builder +++ b/docker/Dockerfile-go-builder @@ -1,6 +1,6 @@ FROM golang:1.23.0-alpine3.20 ARG version -RUN apk add build-base +RUN apk add --no-cache build-base WORKDIR /app COPY go.* ./ RUN go mod download diff --git a/docker/Dockerfile-netclient-multiarch b/docker/Dockerfile-netclient-multiarch index e168d8cb..fbc7bfc1 100644 --- a/docker/Dockerfile-netclient-multiarch +++ b/docker/Dockerfile-netclient-multiarch @@ -13,7 +13,7 @@ FROM alpine:3.16.2 WORKDIR /root/ -RUN apk add --no-cache --update bash libmnl gcompat iptables openresolv iproute2 wireguard-tools +RUN apk add --no-cache bash libmnl gcompat iptables openresolv iproute2 wireguard-tools COPY --from=builder /app/netclient-app ./netclient COPY --from=builder /app/scripts/netclient.sh . RUN chmod 0755 netclient && chmod 0755 netclient.sh diff --git a/docker/Dockerfile-netclient-multiarch-userspace b/docker/Dockerfile-netclient-multiarch-userspace index 4a90c2e5..093af8b6 100644 --- a/docker/Dockerfile-netclient-multiarch-userspace +++ b/docker/Dockerfile-netclient-multiarch-userspace @@ -10,7 +10,7 @@ RUN GOOS=linux CGO_ENABLED=0 /usr/local/go/bin/go build -ldflags="-w -s" -o netc WORKDIR /root/ -RUN apk add --update git build-base libmnl-dev iptables +RUN apk add --no-cache git build-base libmnl-dev iptables RUN git clone https://git.zx2c4.com/wireguard-go && \ cd wireguard-go && \ @@ -28,7 +28,7 @@ FROM alpine:3.16.2 WORKDIR /root/ -RUN apk add --no-cache --update bash libmnl gcompat iptables openresolv iproute2 +RUN apk add --no-cache bash libmnl gcompat iptables openresolv iproute2 COPY --from=builder /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/ COPY --from=builder /app/netclient-app ./netclient COPY --from=builder /app/scripts/netclient.sh .