Update Dockerfile to work with Next.js (#12119)

* Update Dockerfile to work with Next.js

- Update to Node 18
- Do not run as root, this also works better with Node
  privilege-dropping.
- Update README with new run instructions and adding the
  `--rm` flag to avoid leaving a bunch of unused Docker
  containers.
- Also change README to recommend building the image locally.
  Image builds are pretty fast and the uploaded images get
  outdated pretty quickly.

* Add .dockerignore to avoid sending large build contexts

* Typo
This commit is contained in:
Daniël de Kok 2023-01-18 18:15:47 +01:00 committed by GitHub
parent 794cea6907
commit 668ec989ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 32 deletions

9
website/.dockerignore Normal file
View File

@ -0,0 +1,9 @@
.cache/
.next/
public/
node_modules
.npm
logs
*.log
npm-debug.log*
quickstart-training-generator.js

View File

@ -1,16 +1,14 @@
FROM node:11.15.0 FROM node:18
WORKDIR /spacy-io USER node
RUN npm install -g gatsby-cli@2.7.4
COPY package.json .
COPY package-lock.json .
RUN npm install
# This is so the installed node_modules will be up one directory # This is so the installed node_modules will be up one directory
# from where a user mounts files, so that they don't accidentally mount # from where a user mounts files, so that they don't accidentally mount
# their own node_modules from a different build # their own node_modules from a different build
# https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders # https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders
WORKDIR /spacy-io/website/ WORKDIR /home/node
COPY --chown=node package.json .
COPY --chown=node package-lock.json .
RUN npm install
WORKDIR /home/node/website/

View File

@ -41,33 +41,27 @@ If you'd like to do this, **be sure you do _not_ include your local
`node_modules` folder**, since there are some dependencies that need to be built `node_modules` folder**, since there are some dependencies that need to be built
for the image system. Rename it before using. for the image system. Rename it before using.
```bash First build the Docker image. This only needs to be done on the first run
docker run -it \ or when changes are made to `Dockerfile` or the website dependencies:
-v $(pwd):/spacy-io/website \
-p 8000:8000 \
ghcr.io/explosion/spacy-io \
gatsby develop -H 0.0.0.0
```
This will allow you to access the built website at http://0.0.0.0:8000/ in your
browser, and still edit code in your editor while having the site reflect those
changes.
**Note**: If you're working on a Mac with an M1 processor, you might see
segfault errors from `qemu` if you use the default image. To fix this use the
`arm64` tagged image in the `docker run` command
(ghcr.io/explosion/spacy-io:arm64).
### Building the Docker image
If you'd like to build the image locally, you can do so like this:
```bash ```bash
docker build -t spacy-io . docker build -t spacy-io .
``` ```
This will take some time, so if you want to use the prebuilt image you'll save a You can then build and run the website with:
bit of time.
```bash
docker run -it \
--rm \
-v $(pwd):/home/node/website \
-p 3000:3000 \
spacy-io \
npm run dev -- -H 0.0.0.0
```
This will allow you to access the built website at http://0.0.0.0:3000/ in your
browser, and still edit code in your editor while having the site reflect those
changes.
## Project structure ## Project structure