Docker + Ubuntu 安装 nodejs,redis 生成新镜像

来源:互联网 发布:淘宝优惠券模板 编辑:程序博客网 时间:2024/05/22 04:59

Docker + Ubuntu 安装 nodejs

Docker 使用

下载 ubuntu 镜像 docker pull ubuntu:14:04
运行容器 docker run -it -d —name containerName ubuntu:14.04 /bin/bash
进入容器 docker attach containerName

Nodejs

下载 nodejs 安装包 wget https://nodejs.org/download/rc/v8.9.1-rc.1/node-v8.9.1-rc.1.tar.gz
解压 tar -zxvf node-v8.9.1-rc.1.tar.gz
进入 nodejs 解压文件夹 cd node-v8.9.1-rc.1
运行 configure 脚本来配置源代码 ./configure
编译 make install
删除下载的安装包 rm node-v8.9.1-rc.1.tar.gz

npm

sudo apt install npm
sudo npm install npm@latest -g

升级 nodejs

sudo npm install -g n
最新版 sudo n latest
稳定版 sudo n stable

使用pm2管理nodejs进程

安装 npm install -g pm2
运行服务 pm2 start app.js –name [appName]
查看状态 pm2 monit
查看单一状态 pm2 describe [app id]
查看log pm2 logs [appName] [–lines 1000]
重启服务 pm2 restart [app id]
停止服务 pm2 stop [app id]
查看应用列表 pm2 list
网页 监控 pm2 web
随系统启动 pm2 startup ubuntu

Redis

wget http://download.redis.io/releases/redis-4.0.2.tar.gz
tar xzf redis-4.0.2.tar.gz
cd redis-4.0.2
make
删除下载的安装包 rm redis-4.0.2.tar.gz

容器 包存 为镜像

容器内 exit 退出容器
查看一下最后修改的容器,看看大小 docker ps -l -s
保存 容器 成镜像 docker commit containerName imageName:versionNumber
用镜像 启动一个容器 docker run -it -d -name newContainerName imageName:versionNumber /bin/bash

大功告成

docker attach newContainerName

映射容器端口

输出容器端口号
docker inspect containerName | grep IPAddress
将主机的8001 映射给容器的8000 端口
iptables -t nat -A DOCKER -p tcp –dport 8001 -j DNAT –to-destination 172.17.0.2:8000

NODE支持

阿里云oss

npm install co
npm install ali-oss