运行一个容器,安装nodejs
root@d5f6a138a4da:/opt/nodejs# wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh => Downloading nvm as script to '/root/.nvm' => Appending source string to /root/.profile => Close and reopen your terminal to start using nvm root@d5f6a138a4da:/opt/nodejs# source /root/.profile root@d5f6a138a4da:/opt/nodejs# nvm install 0.10 --2015-10-18 16:09:53-- https://nodejs.org/dist/v0.10.40/node-v0.10.40-linux-x64.tar.gz Resolving nodejs.org (nodejs.org)... 104.20.22.46, 104.20.23.46, 2400:cb00:2048:1::6814:162e, ... Connecting to nodejs.org (nodejs.org)|104.20.22.46|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 6128131 (5.8M) [application/gzip] Saving to: '/root/.nvm/bin/node-v0.10.40-linux-x64/node-v0.10.40-linux-x64.tar.gz' 100%[++++++++++++++++++++++++++======================================================================================>] 6,128,131 22.1KB/s in 2m 45s 2015-10-18 16:16:03 (27.9 KB/s) - '/root/.nvm/bin/node-v0.10.40-linux-x64/node-v0.10.40-linux-x64.tar.gz' saved [6128131/6128131] Now using node v0.10.40 (npm v1.4.28)
提交
$ docker commit -m "add nodejs" -a "sunzy" d5f6a138a4da sunzy/hexo:v1.0 a4ce5fe396375ed99523c7bafbba1a9edc685068620db42eaafea4ed0c818680
基于提交的镜像运行
$ docker run -it --name hexo-test -v /opt/nodejs/ -p 5000:5000 sunzy/hexo /bin/bash root@73ae2263e4a3:/opt/nodejs# npm install -g hexo-cli bash: npm: command not found root@73ae2263e4a3:/# cd ~ root@73ae2263e4a3:~# pwd /root root@73ae2263e4a3:~# ls -a . .. .bash_history .bashrc .profile
在HOME目录下没有了nvm的目录并且无法运行npm命令……
这是为啥?docker不至于会在提交后把HOME目录初始化吧?
同样的机器上试试这个
docker run -it --name hexo-test -v /opt/nodejs/ -p 5000:5000 sunzy/hexo:v1.0 /bin/bash
你commit的时候加上了v1.0的tag