Docker + Ubuntu 安裝 nodejs,redis 生成新映象
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 [email protected] -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
容器 包存 為映象
容器內 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