自定义 node.js Docker 镜像

玖亖伍
2023-10-26 / 0 评论 / 262 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2023年10月26日,已超过392天没有更新,若内容或图片失效,请留言反馈。

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 .

参考

0

评论 (0)

取消