提交 2e3a9720 编写于 作者: V Vinci Rufus 提交者: Tim Neutkens

Update the docker multistage to copy only the necessary files (#9899)

* copy only the necessary files during stage 2 in multi-stage.

* update readme
上级 d166840e
......@@ -9,6 +9,8 @@ RUN yarn build && yarn --production
# And then copy over node_modules, etc from that stage to the smaller base image
FROM mhart/alpine-node:base
WORKDIR /app
COPY --from=builder /app .
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/next.config.js ./next.config.js
EXPOSE 3000
CMD ["node_modules/.bin/next", "start"]
......@@ -30,7 +30,13 @@ docker build -t next-app .
docker build -t next-app -f ./Dockerfile.multistage .
```
Run it:
Alternatively you can add these commands as scripts to your package.json and simply run
`yarn build-docker`
or
`yarn build-docker-multistage`
Run the docker image:
```bash
docker run --rm -it \
......@@ -39,6 +45,8 @@ docker run --rm -it \
next-app
```
or use `yarn build-docker-multistage`
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
```bash
......
......@@ -4,7 +4,10 @@
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
"start": "next start",
"build-docker": "docker build -t next-app .",
"build-docker-multistage": "docker build -t next-app -f ./Dockerfile.multistage .",
"run-docker": "docker run --rm -it -p 3000:3000 -e 'API_URL=https://example.com' next-app"
},
"dependencies": {
"next": "latest",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册