Dockerfile-14.16.1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
FROM ubuntu:20.04
RUN apt-get update && \
apt-get install -y curl && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash && \
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" && \
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \
nvm install 14.16.1 && \
nvm use 14.16.1 && \
npm install -g nrm yarn && \
nrm use taobao && \
ln -sf /root/.nvm/versions/node/v14.16.1/bin/node /bin/node && \
ln -sf /root/.nvm/versions/node/v14.16.1/bin/npm /bin/npm && \
ln -sf /root/.nvm/versions/node/v14.16.1/bin/yarn /bin/yarn && \

# clean up
apt remove -y --auto-remove curl && \
apt clean && \
rm -rf /var/lib/apt/lists/*
CMD ["node"]

Dockerfile-16.17

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
FROM ubuntu:20.04
RUN apt-get update && \
apt-get install -y curl && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash && \
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" && \
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \
nvm install 16.17.0 && \
nvm use 16.17.0 && \
npm install -g nrm pnpm && \
nrm use taobao && \
ln -sf /root/.nvm/versions/node/v16.17.0/bin/node /bin/node && \
ln -sf /root/.nvm/versions/node/v16.17.0/bin/npm /bin/npm && \
ln -sf /root/.nvm/versions/node/v16.17.0/bin/pnpm /bin/pnpm && \

# clean up
apt remove -y --auto-remove curl && \
apt clean && \
rm -rf /var/lib/apt/lists/*
CMD ["node"]

Readme

构建镜像

  • 在和dockerfile同级目录内执行
    1
    2
    3
    docker build -f Dockerfile-14.16.1 -t ubuntu-node:v14.16-build .
    docker build -f Dockerfile-16.17.0 -t ubuntu-node:v16.17-build .

  • 无缓存方式构建
    1
    2
    3
    docker build --no-cache -f Dockerfile-14.16.1 -t ubuntu-node:v14.16-build .
    docker build --no-cache -f Dockerfile-16.17.0 -t ubuntu-node:v16.17-build .

用法:打包完就删除容器

1
2
3
docker run  --rm  ubuntu-node:v16.17-build pnpm install && pnpm build

docker run --rm ubuntu-node:v14.16-build yarm install && yarn build

举个栗子

1
2
3
docker run --rm -it -w /app -v /data/www/website:/app ubuntu-node:v16.17-build pnpm install 

docker run --rm -it -w /app -v /data/www/website:/app ubuntu-node:v16.17-build pnpm build