指定版本
查看Dockerfile
cat Dockerfile
FROM alpine:3.10.2
ENV NODE_VERSION 14.5.0
MAINTAINER heyuze
RUN apk add --no-cache curl gcc g++ python make linux-headers
&& curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION.tar.xz"
&& tar -xf "node-v$NODE_VERSION.tar.xz"
&& cd "node-v$NODE_VERSION"
&& ./configure
&& make -j$(getconf _NPROCESSORS_ONLN)
&& make install
&& cd ..
&& rm -Rf "node-v$NODE_VERSION"
&& rm "node-v$NODE_VERSION.tar.xz"
CMD [ "node" ]
使用Dockerfile构建镜像
[root@heyuze ~]# docker build -t alpine-nodejs:v14.5.0 .
查看构建好的镜像
[root@heyuze ~]# docker images|grep alpine-nodejs
harbor.aimmcloud.cn/aimm/alpine-nodejs v14.5.0 235175ed9068 32 seconds ago 339MB
查看node,npm,pm2版本
[root@heyuze ~]# docker run --rm alpine-nodejs:v14.5.0 node -v
v14.5.0
[root@heyuze ~]# docker run --rm alpine-nodejs:v14.5.0 npm -v
6.14.5
[root@heyuze ~]# docker run --rm alpine-nodejs:v14.5.0 pm2 -v
-------------
__/\\\\\\\____/\\____________/\\____/\\\\\_____
_/\/////////\\_/\\\________/\\\__/\///////\\___
_/\\_______/\\_/\//\\____/\//\\_///______//\\__
_/\\\\\\/__/\\///\/\/_/\\___________/\/___
_/\/////////____/\\__///\/___/\\________/\//_____
_/\\_____________/\\____///_____/\\_____/\//________
_/\\_____________/\\_____________/\\___/\/___________
_/\\_____________/\\_____________/\\__/\\\\\\\\_
_///______________///______________///__///////////////__
Runtime Edition
PM2 is a Production Process Manager for Node.js applications
with a built-in Load Balancer.
Start and Daemonize any application:
$ pm2 start app.js
Load Balance 4 instances of api.js:
$ pm2 start api.js -i 4
Monitor in production:
$ pm2 monitor
Make pm2 auto-boot at server restart:
$ pm2 startup
To go further checkout:
http://pm2.io/
-------------
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
4.5.6
给镜像打tag
[root@heyuze ~]# docker tag alpine-nodejs:v14.5.0 heyuze/nodejs:v14.5.0
将镜像push到仓库
[root@heyuze ~]# docker push heyuze/nodejs
The push refers to repository [docker.io/heyuze/nodejs]
f5e26fb32437: Pushed
03901b4a2ea8: Pushed
v14.5.0: digest: sha256:25022611bd19acc6cd7f4b8e357ecd55fc27f0bde494d41e272b53c4b3cb9eef size: 741
使用默认版本
查看Dockerfile
cat Dockerfile
FROM alpine:latest
MAINTAINER yuze
RUN apk add nodejs
RUN apk add npm
CMD [ "node" ]
使用Dockerfile构建镜像
root@heyuze:/data/docker# docker build -t alpine-nodejs .
查看构建好的镜像
root@heyuze:/data/docker# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine-nodejs latest 1857723a956b 2 minutes ago 62.9MB