Skip to content

Commit af38232

Browse files
steinbeckclaude
andcommitted
build: use Alpine Linux for minimal Docker image (~9MB)
Inspired by PR #3 (ferchault). Switch from Ubuntu 24.04 to Alpine 3.21 for both build and runtime stages. Static linking eliminates runtime dependencies, producing a ~9MB image instead of ~80MB. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3f56ceb commit af38232

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

Dockerfile

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
1-
FROM ubuntu:24.04 AS builder
1+
FROM alpine:3.21 AS builder
22

3-
RUN apt-get update && \
4-
apt-get -y install curl gcc make zlib1g-dev && \
5-
apt-get -y clean && \
6-
rm -rf /var/lib/apt/lists/*
3+
RUN apk add --no-cache build-base curl zlib-dev
74

85
WORKDIR /build
96

107
# Download and build nauty
118
RUN curl -L -o nauty2_9_3.tar.gz https://users.cecs.anu.edu.au/~bdm/nauty/nauty2_9_3.tar.gz \
129
&& tar xzf nauty2_9_3.tar.gz \
1310
&& cd nauty2_9_3 \
14-
&& ./configure && make
11+
&& ./configure && make -j4
1512

16-
# Copy source and build surge
13+
# Copy source and build surge (static linking for minimal runtime image)
1714
COPY src/ /build/src/
1815
WORKDIR /build/src
1916
RUN make surge \
2017
NAUTY=/build/nauty2_9_3 \
2118
NAUTYLIB=/build/nauty2_9_3 \
22-
CCOPT="-O3"
19+
CCOPT="-O3 -static"
2320

24-
# Runtime image
25-
FROM ubuntu:24.04
26-
27-
RUN apt-get update && \
28-
apt-get -y install zlib1g && \
29-
apt-get -y clean && \
30-
rm -rf /var/lib/apt/lists/*
21+
# Minimal runtime image (~9MB)
22+
FROM alpine:3.21
3123

3224
COPY --from=builder /build/src/surge /usr/local/bin/surge
3325

0 commit comments

Comments
 (0)