Docker/多指令:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
创建页面,内容为“== 标题文字 == {{shc|<syntaxhighlight lang="bash"> # 用nohup框起来,不然npm start执行了之后不会执行后面的 CMD nohup sh -c 'npm run beta && ngi…”
 
Kangkk​(留言 | 贡献)
 
(未显示同一用户的4个中间版本)
第2行: 第2行:
{{shc|<syntaxhighlight lang="bash">
{{shc|<syntaxhighlight lang="bash">
# 用nohup框起来,不然npm start执行了之后不会执行后面的
# 用nohup框起来,不然npm start执行了之后不会执行后面的
CMD nohup sh -c 'npm run beta && nginx -g "daemon off;"'</syntaxhighlight>|$|/home/kangkk}}
CMD nohup sh -c 'npm run beta && npm run prod'</syntaxhighlight>|$|/home/kangkk}}


或者  
或者  


{{shc|<syntaxhighlight lang="bash">
{{shc|<syntaxhighlight lang="bash">
ENTRYPOINT ["./entrypoint.sh"]</syntaxhighlight>|$|/home/kangkk}}
ENTRYPOINT ["sh", "/home/node/app/entrypoint.sh"]</syntaxhighlight>|$|/home/kangkk}}


{{Hc|entrypoint.sh|nohup npm start &
{{Hc|entrypoint.sh|<pre>
nohup node ./server/server.js &}}
#!/bin/bash
 
nohup npm run beta &
nginx -g "daemon off;"
tail -f /dev/null</pre>}}
 
dockerfile 文件示例。
 
<pre>
FROM alpine:3.13.5
MAINTAINER kangkk "365@kangkk.com"
RUN apk add nginx nodejs npm && mkdir /run/nginx/
 
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY ssl /etc/nginx/ssl
 
EXPOSE 80 443
 
WORKDIR /home/node/app
COPY . $WORKDIR
RUN ["chmod", "+x", "entrypoint.sh"]
 
RUN npm install --production --registry=http://registry.npm.qiwoo.org
# RUN npm install pm2 -g --registry=http://registry.npm.qiwoo.org
# RUN pm2 start npm -- run dev
#RUN npm run prod &
 
# ENTRYPOINT ["npm", "run"]
# CMD ["npm", "run", "prod"]
 
# nginx默认是以后台模式启动的,Docker未执行自定义的CMD之前,nginx的pid是1,执行到CMD之后,nginx就在后台运行,bash或sh脚本的pid变为1。
# 当执行完自定义CMD,nginx容器退出。为了保持nginx的容器不退出,应该关闭nginx后台运行
 
# RUN echo "daemon off;" >>/etc/nginx/nginx.conf
# RUN nginx -g "daemon off;"
# ENTRYPOINT ["nginx", "-g", "daemon off;"]
 
# RUN实际上运行一个命令并提交结果; CMD在构建时不执行任何操作,但指定镜像的预期命令
# CMD ["nginx", "-g", "daemon off;"]
# ENTRYPOINT ["bin/bash"]
 
# CMD ["./entrypoint.sh"]
ENTRYPOINT ["sh", "/home/node/app/entrypoint.sh"]
#
# 用nohup框起来,不然npm start执行了之后不会执行后面的
# CMD nohup sh -c 'npm run beta' && nginx -g "daemon off;"</pre>