Skip to content

Commit 7741ea7

Browse files
authored
Update Dockerfile
fix nvm install in docker
1 parent f57e588 commit 7741ea7

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Dockerfile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@ RUN apt-get update && apt-get install -y \
1111
ENV NVM_DIR=/usr/local/nvm
1212
ENV NODE_VERSION=20.11.1
1313

14-
# 安装 nvm
15-
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
16-
&& source $NVM_DIR/nvm.sh \
17-
&& nvm install $NODE_VERSION \
18-
&& nvm alias default $NODE_VERSION \
19-
&& nvm use default
14+
# Use bash for the shell
15+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
16+
17+
# Create a script file sourced by both interactive and non-interactive bash shells
18+
ENV BASH_ENV /home/user/.bash_env
19+
RUN touch "${BASH_ENV}"
20+
RUN echo '. "${BASH_ENV}"' >> ~/.bashrc
21+
22+
# Download and install nvm
23+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | PROFILE="${BASH_ENV}" bash
24+
RUN echo node > .nvmrc
25+
RUN nvm install $NODE_VERSION
26+
RUN nvm alias default $NODE_VERSION
27+
RUN nvm use default
2028

2129
# 确保后续命令可以使用 nvm 和 node
2230
ENV PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
2331

2432
# 可选:验证 Node.js 和 npm 版本
25-
RUN node -v && npm -v
33+
RUN node -v && npm -v

0 commit comments

Comments
 (0)