webp_server_go/Dockerfile
wood chen 85e0534523 chore(Dockerfile): Update Dockerfile to use Alpine Linux and refactor package management
Update Dockerfile to use Alpine Linux for base image and refactor package management to use apk instead of apt. Also, clean up cache directories after installing packages.
2024-10-23 01:16:23 +08:00

25 lines
861 B
Docker

FROM golang:1.23-bookworm AS builder
ARG IMG_PATH=/opt/pics
ARG EXHAUST_PATH=/opt/exhaust
RUN apt update && apt install --no-install-recommends libvips-dev -y && mkdir /build
COPY go.mod /build
RUN cd /build && go mod download
COPY . /build
RUN cd /build && sed -i "s|.\/pics|${IMG_PATH}|g" config.json \
&& sed -i "s|\"\"|\"${EXHAUST_PATH}\"|g" config.json \
&& sed -i 's/127.0.0.1/0.0.0.0/g' config.json \
&& go build -ldflags="-s -w" -o webp-server .
FROM debian:bookworm-slim
RUN apt update && apt install --no-install-recommends libvips ca-certificates -y && rm -rf /var/lib/apt/lists/* && rm -rf /var/cache/apt/archives/*
COPY --from=builder /build/webp-server /usr/bin/webp-server
COPY --from=builder /build/config.json /etc/config.json
WORKDIR /opt
VOLUME /opt/exhaust
CMD ["/usr/bin/webp-server", "--config", "/etc/config.json"]