Skip to content

Commit 4245010

Browse files
authored
Try using node-slim Docker image instead of alpine (#223)
1 parent 0299186 commit 4245010

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

Dockerfile

+15-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# We use the alpine image because of its small size. The alternative considered was the "slim" image, but it is larger
1818
# and we already use alpine (without issues) in other projects, so the size reduction seems worth it.
19-
FROM node:18-alpine AS build
19+
FROM node:18-slim AS build
2020
WORKDIR /app
2121
RUN npm install -g pnpm
2222
# Copy just the "pnpm-lock.yaml" file and use "pnpm fetch" to download all dependencies just from the lockfile. This
@@ -39,13 +39,13 @@ LABEL application="airnode-feed" description="Airnode feed container"
3939
FROM build AS deployed-airnode-feed
4040

4141
RUN pnpm --filter=@api3/airnode-feed --prod deploy deployed-airnode-feed
42-
FROM node:18-alpine as airnode-feed
42+
FROM node:18-slim as airnode-feed
4343
WORKDIR /app
4444
ENV NODE_ENV=production
4545

46-
RUN addgroup -S deployed-airnode-feed && \
47-
adduser -h /app -s /bin/false -S -D -H -G deployed-airnode-feed deployed-airnode-feed && \
48-
chown -R deployed-airnode-feed /app
46+
RUN addgroup --system deployed-airnode-feed && \
47+
adduser --home /app --shell /bin/false --system --disabled-password --ingroup deployed-airnode-feed deployed-airnode-feed && \
48+
chown --recursive deployed-airnode-feed:deployed-airnode-feed /app
4949
USER deployed-airnode-feed
5050

5151
COPY --chown=deployed-airnode-feed:deployed-airnode-feed --from=deployed-airnode-feed /app/deployed-airnode-feed .
@@ -58,17 +58,21 @@ LABEL application="signed-api" description="Signed API container"
5858
FROM build AS deployed-signed-api
5959

6060
RUN pnpm --filter=@api3/signed-api --prod deploy deployed-signed-api
61-
FROM node:18-alpine as signed-api
61+
FROM node:18-slim as signed-api
6262
WORKDIR /app
6363
ENV NODE_ENV=production
6464

65-
# Make sure the non-root user can bind to port 80.
66-
RUN apk add --no-cache libcap
65+
# Update package lists and install libcap
66+
RUN apt-get update && \
67+
apt-get install --no-install-recommends -y libcap2-bin && \
68+
rm -rf /var/lib/apt/lists/*
69+
# Set capabilities to allow Node.js to bind to well-known ports (<1024) as a non-root user
6770
RUN setcap 'cap_net_bind_service=+ep' /usr/local/bin/node
6871

69-
RUN addgroup -S deployed-signed-api && \
70-
adduser -h /app -s /bin/false -S -D -H -G deployed-signed-api deployed-signed-api && \
71-
chown -R deployed-signed-api /app
72+
73+
RUN addgroup --system deployed-signed-api && \
74+
adduser --home /app --shell /bin/false --system --disabled-password --ingroup deployed-signed-api deployed-signed-api && \
75+
chown --recursive deployed-signed-api:deployed-signed-api /app
7276
USER deployed-signed-api
7377

7478
COPY --chown=deployed-signed-api:deployed-signed-api --from=deployed-signed-api /app/deployed-signed-api .

0 commit comments

Comments
 (0)