Commit 2e3a9720 authored by Vinci Rufus's avatar Vinci Rufus Committed by 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
parent d166840e
...@@ -9,6 +9,8 @@ RUN yarn build && yarn --production ...@@ -9,6 +9,8 @@ RUN yarn build && yarn --production
# And then copy over node_modules, etc from that stage to the smaller base image # And then copy over node_modules, etc from that stage to the smaller base image
FROM mhart/alpine-node:base FROM mhart/alpine-node:base
WORKDIR /app 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 EXPOSE 3000
CMD ["node_modules/.bin/next", "start"] CMD ["node_modules/.bin/next", "start"]
...@@ -30,7 +30,13 @@ docker build -t next-app . ...@@ -30,7 +30,13 @@ docker build -t next-app .
docker build -t next-app -f ./Dockerfile.multistage . 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 ```bash
docker run --rm -it \ docker run --rm -it \
...@@ -39,6 +45,8 @@ docker run --rm -it \ ...@@ -39,6 +45,8 @@ docker run --rm -it \
next-app next-app
``` ```
or use `yarn build-docker-multistage`
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
```bash ```bash
......
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
"scripts": { "scripts": {
"dev": "next", "dev": "next",
"build": "next build", "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": { "dependencies": {
"next": "latest", "next": "latest",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment