使用Docker发布Node.js服务

2017-08-11  本文已影响0人  爱吃酸菜的_鱼

创建docker file


# Use an official node.js LTS version
FROM node:boron
# set http.sslverify false
RUN git config --global http.sslverify false
# create work dir
RUN mkdir /app
# set work dir
WORKDIR /app
# clone from repo
RUN git clone https://username:password@git.repo/repo.git
# set work dir
WORKDIR /app/repo
# npm i 
RUN npm i -d
# set NODE_ENV=production
ENV NODE_ENV=production
# Bundle app source
# also you can install pm2 ,and use pm2 start app 
CMD [ "node", "." ]
# use user node
USER node

docker build

sudo docker build --no-cache -t tag_name
--no-cache 不要使用缓存

推送到docker仓库

  1. 在推送之前应该打上标签 仓库地址/名称
sudo docker tag xxxxxxxxx 127.0.0.1:5000/test:version1.0
  1. 推送
sudo docker push  127.0.0.1:5000/test:version1.0
  1. 查看

搭建私有仓库

这个直接看官网的就可以的 但是要注意的是 registry2默认的是https

要修改一下 /etc/docker/daemon.json 这个文件 加上 [这个文件没有就创建 不过要注意是json格式的]

  "insecure-registries" : ["myregistrydomain.com:5000"],

Ref: deploying http registry
Ref: docker registry

上一篇 下一篇

猜你喜欢

热点阅读