Dockerize RedwoodJS

Great work! :rocket:

I found below particularly interesting. Been trying to get Yarn 3 cache to work myself.

RUN --mount=type=cache,target=/root/.yarn/berry/cache \
    --mount=type=cache,target=/root/.cache yarn install --immutable --inline-builds

I have just updated redwoodjs/docker to version 1.3.1 and I’m looking forward to a PR. Ping me for any input! :wave:t2:

This is my solution

Create docker-compose.yml

# docker-compose.yml
version: "3.9"
services:
  web:
    build:
      context: .
      dockerfile: ./Dockerfile
    image: your_name_image
    ports:
      - "8910:8910"
    env_file:
      - .env
    environment:
      - NODE_ENV=production

Create Dockerfile

# Dockerfile
FROM node:14-alpine as base

WORKDIR /app

COPY package.json package.json
COPY web/package.json web/package.json
COPY api/package.json api/package.json
COPY yarn.lock yarn.lock
RUN yarn install

COPY redwood.toml .
COPY graphql.config.js .

FROM base as web_build

COPY web web
RUN yarn rw build web

FROM base as api_build

COPY api api
RUN yarn rw build api

FROM node:14-alpine

WORKDIR /app

# Only install API packages to keep image small
COPY api/package.json .

RUN yarn install && yarn add react react-dom @redwoodjs/api-server @redwoodjs/internal prisma

COPY graphql.config.js .
COPY redwood.toml .
COPY api api

COPY --from=web_build /app/web/dist /app/web/dist
COPY --from=api_build /app/api/dist /app/api/dist
COPY --from=api_build /app/api/db /app/api/db
COPY --from=api_build /app/node_modules/.prisma /app/node_modules/.prisma

# Entrypoint to @redwoodjs/api-server binary
CMD [ "yarn", "rw-server", "--port", "8910" ]

Remember create .dockerignore

4 Likes

Thanks for this one !!

Would you be willing to add it here?

This is where we are locating the community work until there is an official Docker Deploy

Thanks!

Al;

I think, it that good idea :slight_smile: @ajoslin103

1 Like

any estimate how soon to expect this done?

Let’s organize this effort!

Details here if you’re interested and available: