centos7 下用docker部署nodejs应用

Node.js Hello World

Node.js Hello World on CentOS using docker.

Prerequisites

Getting Started

  • SSH into centos7,下载代码:

    客户端连接
    cd /opt/www
    git clone git@github.com:fffy2366/docker-node-hello.git
    
  • 安装依赖包:

    cd docker-node-hello
    make install
    
  • 创建 docker image:

    make build
    # docker build -t gasi/centos-node-hello .
    
  • Run app:

    make run-container
    # docker run -p 49160:8080 -d gasi/centos-node-hello
    
  • Install curl:

    sudo apt-get install curl
    
  • Get mapped port (last column) using, e.g. 49160:

    docker ps
    
    > # Example
    > ID                  IMAGE                           COMMAND              CREATED             STATUS              PORTS
    > ecce33b30ebf        gasi/centos-node-hello:latest   node /src/index.js   10 seconds ago      Up 9 seconds        49160->8080
    
  • Test app using the port in previous step, e.g. 49160:

    curl localhost:<port>
    
    # Example
    # curl localhost:49160
    

    It should print Hello World to the console.

Acknowledgements

Many thanks to @shykes and @unclejack for their support on IRC as well as the
@dotCloud team for docker.

Ref:https://docs.docker.com/examples/nodejs_web_app/

常用命令

  • 删除没有TAG的image(TAG为):
    docker rmi -f (docker images | grep "^<none>" | awk "{print3}”)

Ref:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值