Dockerfile:
FROM ghcr.io/linuxserver/baseimage-alpine:3.18
SHELL ["/bin/bash", "-c"]
RUN echo $'#!/bin/bash \n\
set -e \n\
\n\
# Run command with node if the first argument contains a "-" or is not a system command. The last \n\
# part inside the "{}" is a workaround for the following bug in ash/dash: \n\
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874264 \n\
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then \n\
set -- node "$@" \n\
fi \n\
\n\
exec "$@"' > /usr/local/bin/docker-entrypoint.sh
RUN chmod a+x /usr/local/bin/docker-entrypoint.sh
RUN groups
RUN users
RUN whoami
RUN groupadd --non-unique --gid 1000 node
RUN useradd --non-unique --uid 1000 --gid node --shell /bin/bash --create-home node
ENV NODE_VERSION 21.1.0
ENV ARCH x64
RUN curl -fsSLO --compressed "https://unofficial-builds.nodejs.org/download/release/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH-musl.tar.xz"
RUN ls -lha
RUN tar -xJf "node-v$NODE_VERSION-linux-$ARCH-musl.tar.xz" -C /usr/local --strip-components=1 --no-same-owner
RUN rm -f "node-v$NODE_VERSION-linux-$ARCH-musl.tar.xz"
RUN ln -s /usr/local/bin/node /usr/local/bin/nodejs
RUN apk add --no-cache libstdc++
RUN node --version
RUN npm --version
# RUN wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.bashrc" SHELL="$(which bash)" bash -
RUN npm config set registry https://registry.npmmirror.com
RUN npm install -g pm2
RUN npm install -g pnpm
RUN pnpm --version
RUN rm -rf /tmp/* $HOME/.cache
ENTRYPOINT ["docker-entrypoint.sh"]
CMD [ "node" ]
build:
docker build --progress plain --rm --tag gsw945/node:v0.0.1 .
参考
- 安装 | pnpm - 使用 npm 安装
- https://github.com/nodejs/docker-node/blob/main/21/alpine3.18/Dockerfile
- https://github.com/linuxserver/docker-baseimage-alpine/pkgs/container/baseimage-alpine/137430303?tag=3.18
- How to write commands with multiple lines in Dockerfile while preserving the new lines?
- Dockerfile replicate the host user UID and GID to the image
评论 (0)