I also have a Docker usecase. For my needs I’m wanting to package web & api in separate containers. It was easy enough to get the compiled web app running in a container served by nginx, however the api took some hackery.
api dockerfile:
FROM node:lts-alpine
ENV PORT 8911
RUN apk --no-cache add git
COPY . /app/api
COPY docker/ /app/
WORKDIR /app
RUN yarn install
RUN cd api && yarn install && yarn add @redwoodjs/core
RUN yarn rw build api
EXPOSE $PORT
CMD yarn rw dev api
So what I’m doing here is copying everything from /api into /app/api, and then I created a /docker dir which contains the following files that are copied into /app:
- .babelrc.js
- .env.defaults
- babel.config.js
- package.json
- redwood.toml
I did this for two reasons, one is that my Dockerfile for api lives in the /api dir which means you can’t reference files outside of that directory. The second reason is that I wanted to modify some of the files without touching the originals. So it’s a little messy.
docker/package.json:
{
"name": "app",
"version": "0.0.0",
"private": true,
"dependencies": {
"@redwoodjs/api": "^0.12.0",
"@redwoodjs/core": "^0.12.0",
"netlify-plugin-prisma-provider": "^0.3.0"
}
}
docker/.babelrc.js
module.exports = { extends: 'babel.config.js' }
I also had to add @redwoodjs/core
to /api/package.json otherwise the commands aren’t found.
My docker-compose file:
version: '3.6'
services:
api:
image: app-api
build:
context: ./api
dockerfile: Dockerfile
ports:
- 8911:8911
web:
image: app-web
build:
context: ./web
dockerfile: Dockerfile
ports:
- 8910:8910
Another issue is that requests from the web container are currently routed to itself, e.g. http://localhost:8910/.netlify/functions/graphql
It looks like this could be fixed by changing apiProxyPath
in redwood.toml, but for now I’m just proxying the request in my nginx config.
Otherwise this seems to work pretty well.