New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eggjs + docker 最佳实践 #1431

Closed
Quinton opened this Issue Sep 15, 2017 · 16 comments

Comments

Projects
None yet
8 participants
@Quinton
Copy link

Quinton commented Sep 15, 2017

docker该如何配合eggjs work特性让项目稳定的运行?

@atian25

This comment has been minimized.

Copy link
Member

atian25 commented Sep 15, 2017

就在 docker 里面跑 egg-scripts start 即可,不需要 --daemon 了。

@thonatos

This comment has been minimized.

Copy link
Member

thonatos commented Sep 16, 2017

#package.json

{
  "scripts": {
    "start": "egg-scripts start",
  }
}

Dockerfile

FROM node:8.6.0-alpine

RUN apk --update add tzdata \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && apk del tzdata

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

# add npm package
COPY package.json /usr/src/app/package.json

RUN npm i --registry=https://registry.npm.taobao.org

# copy code
COPY . /usr/src/app

EXPOSE 7001

CMD npm start

8.0.0 egg-socket-io sticky 会有问题,如果没特殊要求换高版本吧

@Quinton

This comment has been minimized.

Copy link
Author

Quinton commented Sep 17, 2017

提前COPY package.json && npm install ,docker构建镜像,加快速度
另:用yarn替代npm可以加快镜像构建,大概平均节省30s

@atian25

This comment has been minimized.

Copy link
Member

atian25 commented Sep 17, 2017

@thonatos

This comment has been minimized.

Copy link
Member

thonatos commented Sep 17, 2017

tips

  • RUN/COPY 是分层的,package.json 提前,只要没修改,就不会重新安装包
  • npm/yarn/cnpm 新版并木有速度太大差距哇,关键是源
  • 添加时区可以有效避免部分包如 aliyun-oss 因时区差异导致的签名失败问题(海外Region)

感受一下速度吧

2017-09-17 12 08 12

@abos5

This comment has been minimized.

Copy link

abos5 commented Sep 29, 2017

RUN apk --update add tzdata

请问这一步能否用到国内镜像呢,部分网络好慢

@atian25

This comment has been minimized.

Copy link
Member

atian25 commented Sep 29, 2017

这块属于具体 docker 系统的命令了,可以自行 google 下如何修改 alpine 的源

@popomore

This comment has been minimized.

Copy link
Member

popomore commented Sep 29, 2017

@abos5 可以自己找下国内 apk 镜像

@VectorHo

This comment has been minimized.

Copy link

VectorHo commented Oct 24, 2017

@thonatos 是什么构建UI,是docker hub 和github 协作那个吗?

@thonatos

This comment has been minimized.

Copy link
Member

thonatos commented Oct 24, 2017

阿里云容器服务

@Yang03

This comment has been minimized.

Copy link

Yang03 commented Jul 31, 2018

npm run start 时不加--daemon,node 在前台运行, gitlab ci job 一直就会在运行状态 @atian25

@thonatos

This comment has been minimized.

Copy link
Member

thonatos commented Aug 1, 2018

@Yang03

CI 不应该跑 egg-scripts start

@Yang03

This comment has been minimized.

Copy link

Yang03 commented Aug 1, 2018

ci 里面跑的是 docker run -p 7001:7001 --name xx__image xx

dockerFile 最后的命令是 npm run start => egg-script start @thonatos

@popomore

This comment has been minimized.

Copy link
Member

popomore commented Aug 1, 2018

docker run -d

@menkeydyvh

This comment has been minimized.

Copy link

menkeydyvh commented Sep 7, 2018

有人知道 docker run egg项目完成后 无法退出继续执行 linux 命令行是怎么回事?
ctrl+c 都退出不到能输入linux命令的状态

@Yang03

This comment has been minimized.

Copy link

Yang03 commented Sep 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment