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.
This commit is contained in:
Peter Dave Hello 2025-04-30 06:55:34 +08:00 committed by GitHub
parent 8c3065482a
commit 105b7dfc1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 6 additions and 6 deletions

View file

@ -11,7 +11,7 @@ FROM alpine:3.21.3
# add a c lib # add a c lib
# set the working directory # set the working directory
WORKDIR /root/ WORKDIR /root/
RUN apk update && apk upgrade RUN apk upgrade --no-cache
RUN apk add --no-cache sqlite RUN apk add --no-cache sqlite
RUN mkdir -p /etc/netclient/config RUN mkdir -p /etc/netclient/config
COPY --from=builder /app/netmaker . COPY --from=builder /app/netmaker .

View file

@ -6,7 +6,7 @@ COPY ./netmaker /root/netmaker
ENV GO111MODULE=auto ENV GO111MODULE=auto
# add a c lib # add a c lib
RUN apk add gcompat iptables wireguard-tools RUN apk add --no-cache gcompat iptables wireguard-tools
# set the working directory # set the working directory
WORKDIR /root/ WORKDIR /root/
RUN mkdir -p /etc/netclient/config RUN mkdir -p /etc/netclient/config

View file

@ -1,6 +1,6 @@
FROM golang:1.23.0-alpine3.20 FROM golang:1.23.0-alpine3.20
ARG version ARG version
RUN apk add build-base RUN apk add --no-cache build-base
WORKDIR /app WORKDIR /app
COPY go.* ./ COPY go.* ./
RUN go mod download RUN go mod download

View file

@ -13,7 +13,7 @@ FROM alpine:3.16.2
WORKDIR /root/ 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/netclient-app ./netclient
COPY --from=builder /app/scripts/netclient.sh . COPY --from=builder /app/scripts/netclient.sh .
RUN chmod 0755 netclient && chmod 0755 netclient.sh RUN chmod 0755 netclient && chmod 0755 netclient.sh

View file

@ -10,7 +10,7 @@ RUN GOOS=linux CGO_ENABLED=0 /usr/local/go/bin/go build -ldflags="-w -s" -o netc
WORKDIR /root/ 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 && \ RUN git clone https://git.zx2c4.com/wireguard-go && \
cd wireguard-go && \ cd wireguard-go && \
@ -28,7 +28,7 @@ FROM alpine:3.16.2
WORKDIR /root/ 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 /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/
COPY --from=builder /app/netclient-app ./netclient COPY --from=builder /app/netclient-app ./netclient
COPY --from=builder /app/scripts/netclient.sh . COPY --from=builder /app/scripts/netclient.sh .