fair-rose
fair-rose13mo ago

How to use Docker with Refine, or any example if possible so that I can refer to it.

Wanted to know how to use Docker with Refine, or any example if possible so that I can refer to it. Because the image I'm able to generate as of now around 1.1GiB in size which is not optimal. Please find below my existing Dockerfile. FROM node:18-alpine AS base Install dependencies only when needed FROM base AS deps Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. RUN apk add --no-cache libc6-compat WORKDIR /app Install dependencies based on the preferred package manager COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ RUN \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ elif [ -f package-lock.json ]; then npm install --omit=dev; \ elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \ else echo "Lockfile not found." && exit 1; \ fi FROM base AS dev WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . Rebuild the source code only when needed FROM base AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry Uncomment the following line in case you want to disable telemetry during the build. ENV NEXT_TELEMETRY_DISABLED 1 RUN npm run build If using npm comment out above and use below instead RUN npm run build Production image, copy all the files and run next FROM base AS runner WORKDIR /app Uncomment the following line in case you want to disable telemetry during runtime. ENV NEXT_TELEMETRY_DISABLED 1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs COPY --from=builder /app/public ./public COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static USER nextjsCMD ["node", "server.js"]
Next.js - Telemetry
Next.js by Vercel is the React framework for production
GitHub
GitHub - nodejs/docker-node at b4117f9333da4138b03a546ec926ef50a315...
Official Docker Image for Node.js :whale: :turtle: :rocket: - GitHub - nodejs/docker-node at b4117f9333da4138b03a546ec926ef50a31506c3
9 Replies
kapa.ai
kapa.ai13mo ago
Hi @rohit7roy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the extracts, there is a Dockerfile configuration example shared by a community member in a Discord support thread. This Dockerfile configuration is for a production environment and it might help you optimize your Docker image size. Here is the Dockerfile configuration:
FROM node:18-alpine

WORKDIR /opt/app

COPY package*.json ./
COPY .npmrc ./

RUN npm ci

COPY . /opt/app

RUN npm run build

FROM node:18-alpine

COPY --from=0 /opt/app/build /opt/app
WORKDIR /opt/app/

ENV NODE_ENV=production

RUN npm install -g serve

CMD serve -l 5000
FROM node:18-alpine

WORKDIR /opt/app

COPY package*.json ./
COPY .npmrc ./

RUN npm ci

COPY . /opt/app

RUN npm run build

FROM node:18-alpine

COPY --from=0 /opt/app/build /opt/app
WORKDIR /opt/app/

ENV NODE_ENV=production

RUN npm install -g serve

CMD serve -l 5000
This Dockerfile uses a multi-stage build process to reduce the final image size. In the first stage, it builds the application and in the second stage, it only copies the built application from the first stage and installs the serve package to serve the application. This way, the final image does not include the development dependencies and intermediate build artifacts, which can significantly reduce the image size. Please note that this is a general example and might need to be adjusted based on your specific application and requirements. You can find the original conversation here (https://discord.com/channels/837692625737613362/1113809508398006332). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai13mo ago
<@956296349287079966> kapa.ai is still learning and improving, please let us know how it did by reacting below
fair-rose
fair-roseOP13mo ago
@kapa.ai I've already seen this answer can you suggest something else for size reduction as well.
kapa.ai
kapa.ai13mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Based on the information provided in the extracts, there are several strategies you can use to reduce the size of your Docker images: 1. Minimize unnecessary dependencies and processes: Try to only include the dependencies that are absolutely necessary for your application to run. This can significantly reduce the size of your Docker images. source (https://refine.dev/blog/docker-run-command/#optimize-container-startup) 2. Use multi-stage builds: Multi-stage builds allow you to separate the build environment from the final runtime environment. This can help to reduce the size of your Docker images by only including the necessary components in the final image. source (https://refine.dev/blog/docker-run-command/#optimize-container-startup) 3. Use a lightweight base image: Using a lightweight base image like Alpine can help to reduce the size of your Docker images. source (https://refine.dev/blog/kubernetes-vs-docker/#ability-to-reduce-the-size) 4. Utilize Docker's caching mechanisms: Docker's layer caching feature can help to reduce the size of your Docker images by reusing layers from previous builds. source (https://refine.dev/blog/docker-run-command/#utilizing-cache-mechanisms) 5. Optimize Docker volume usage: Restrict the number of volumes to only what is required for your application, as each volume has some overhead. Also, enable caching for volumes that frequently access read-only data. source (https://refine.dev/blog/docker-volumes/#optimizing-docker-volume-usage) 6. Set appropriate resource limits: Setting appropriate resource limits can help to prevent resource contention or system overload, which can in turn help to reduce the size of your Docker images. source (https://refine.dev/blog/docker-run-command/#resource-allocation) Remember, these are general strategies and might need to be adjusted based on your specific application and requirements. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai13mo ago
<@956296349287079966> kapa.ai is still learning and improving, please let us know how it did by reacting below
fair-rose
fair-roseOP13mo ago
This results in Generation of static content being served by node and also it doesn’t open the webapp rather just show the files and folders like a file explorer
Omer
Omer13mo ago
Hey, I'm not sure if this question is about Refine. Refine is a meta-framework and essentially uses React platforms available in the market. Please conduct this research for the React platform you use By the way, please do not ask the same question by writing to multiple channels. Thank you for your understanding.
fair-rose
fair-roseOP13mo ago
@Omer As far as I know.
refine is a meta React framework that enables the rapid development of a wide range of web applications. From internal tools, admin panels, B2B apps and dashboards, it serves as a comprehensive solution for building any type of CRUD applications.
refine is a meta React framework that enables the rapid development of a wide range of web applications. From internal tools, admin panels, B2B apps and dashboards, it serves as a comprehensive solution for building any type of CRUD applications.
And being a comprehensive solution should include deployment support as well and not just providing the Netlify homepage link. Specially support for containerization at least.
national-gold
national-gold12mo ago
Hello @Rohit Roy, we've recently added deployment page to our documentation, you can check it here and let us know what you think! https://refine.dev/docs/guides-concepts/deployment/
Deployment | refine
Refine being a meta-framework, it does not have a specific deployment configuration on its own.

Did you find this page helpful?