Closed johnykes closed 4 months ago
Just managed to successfully host it on Docker 😁
steps:
replace the deprecated nuxt-simple-sitemap
with @nuxtjs/sitemap
uncomment in nuxt.config.ts
routeRules: {
'/**': {
prerender: true,
},
},
dockerfile
# build stage
FROM node:18-alpine as build-stage
WORKDIR /app
COPY package.json . COPY pnpm-lock.yaml ./
RUN apk update RUN apk add --no-cache git
RUN npm install -g pnpm@8.6.0
RUN pnpm install
COPY . .
ENV DIRECTUS_URL=${DIRECTUS_URL} ENV DIRECTUS_SERVER_TOKEN=${DIRECTUS_SERVER_TOKEN} ENV SITE_URL=${SITE_URL}
RUN NODE_OPTIONS="--max-old-space-size=4096" pnpm build
FROM node:18-slim as production
COPY --from=build-stage /app/.output /app/.output COPY --from=build-stage /app/node_modules /app/node_modules
EXPOSE 3000
CMD ["node", "/app/.output/server/index.mjs"]
- .dockerignore (not working without this, not sure why :) )
node_modules npm-debug.log Dockerfile docker-compose .dockerignore .git .gitignore README.md LICENSE .vscode
- build
docker build -t test-website --build-arg DIRECTUS_URL='http://host.docker.internal:8055' --build-arg DIRECTUS_SERVER_TOKEN='...' --build-arg SITE_URL='http://localhost:3000' --build-arg NODE_OPTIONS="--max-old-space-size=4096" .
- start docker container
docker run --name test-website --network directus_default -p 3000:3000 -e "DIRECTUS_URL=http://localhost:8055" -e "DIRECTUS_SERVER_TOKEN=..." -e "SITE_URL=https://your_domain" --rm test-website
PS: in production, the DIRECTUS_URL & SITE_URL can't be `localhost`
PS 2: in .directus/docker-compose.yml you need to update CORS, else, the forms won't work
CORS_ENABLED: 'true'
CORS_ORIGIN: 'https://mywebsite.com,http://localhost:3000'
CORS_METHODS: GET,POST
Thanks for the info and glad you got it working! As I do not see any issue outlined here I am going to close this for now, happy to re-open if needed.
Hi guys,
Sorry for bothering.
This repo is 🚀
I would also love to host it on docker. I tried creating a docker file, but I can't make the build part work.
I always get this error
Error: Cannot find module '/app/node_modules/nuxt/bin/nuxt.mjs'
Any idea?