Dockerizing t3 app with mysql database

Hello, im struggling with dockerizing my t3 app and.. idk how to handle that correctly :/ Ive read article on t3 website but i cannot handle running my database/app simultanously, im getting error like that on screen. My first touches with docker, do you have any idea what will be wrong? 🤔 Thanks for any advice! also attaching dockerfile/docker compose: Dockerfile
jsx
##### DEPENDENCIES

FROM --platform=linux/amd64 node:20-alpine AS deps
RUN apk add --no-cache libc6-compat openssl
WORKDIR /app

# Install Prisma Client - remove if not using Prisma

COPY prisma ./

# 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 ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \
fi

##### BUILDER

FROM --platform=linux/amd64 node:20-alpine AS builder
ARG DATABASE_URL
ARG NEXT_PUBLIC_CLIENTVAR
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# ENV NEXT_TELEMETRY_DISABLED 1

RUN \
if [ -f yarn.lock ]; then SKIP_ENV_VALIDATION=1 yarn build; \
elif [ -f package-lock.json ]; then SKIP_ENV_VALIDATION=1 npm run build; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && SKIP_ENV_VALIDATION=1 pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi

##### RUNNER

FROM --platform=linux/amd64 gcr.io/distroless/nodejs20-debian12 AS runner
WORKDIR /app

ENV NODE_ENV production

# ENV NEXT_TELEMETRY_DISABLED 1

COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static

EXPOSE 3000
ENV PORT 3000

CMD ["server.js"]
jsx
##### DEPENDENCIES

FROM --platform=linux/amd64 node:20-alpine AS deps
RUN apk add --no-cache libc6-compat openssl
WORKDIR /app

# Install Prisma Client - remove if not using Prisma

COPY prisma ./

# 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 ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
else echo "Lockfile not found." && exit 1; \
fi

##### BUILDER

FROM --platform=linux/amd64 node:20-alpine AS builder
ARG DATABASE_URL
ARG NEXT_PUBLIC_CLIENTVAR
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# ENV NEXT_TELEMETRY_DISABLED 1

RUN \
if [ -f yarn.lock ]; then SKIP_ENV_VALIDATION=1 yarn build; \
elif [ -f package-lock.json ]; then SKIP_ENV_VALIDATION=1 npm run build; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && SKIP_ENV_VALIDATION=1 pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi

##### RUNNER

FROM --platform=linux/amd64 gcr.io/distroless/nodejs20-debian12 AS runner
WORKDIR /app

ENV NODE_ENV production

# ENV NEXT_TELEMETRY_DISABLED 1

COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static

EXPOSE 3000
ENV PORT 3000

CMD ["server.js"]
docker-compose:
version: "3.9"
services:
kwirk-db:
image: mysql:latest
restart: always
ports:
- 3308:3306
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
container_name: kwirk-mysql
volumes:
- ./data:/docker-entrypoint-initdb.d
kwirk-app:
platform: "linux/amd64"
build:
context: .
dockerfile: Dockerfile
args:
NEXT_PUBLIC_CLIENTVAR: "clientvar"
# image: t3-app
depends_on:
- kwirk-db
working_dir: /app
ports:
- 3000:3000
- 35729:35729
environment:
- DATABASE_URL=${DATABASE_URL}
- UPLOADTHING_SECRET=${UPLOADTHING_SECRET}
# - NEXT_PUBLIC_UPLOADTHING_SECRET=${NEXT_PUBLIC_UPLOADTHING_SECRET}
- UPLOADTHING_APP_ID=${UPLOADTHING_APP_ID}
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
- NEXTAUTH_URL=${NEXTAUTH_URL}
# develop:
# watch:
# - path: ./app/package.json
# action: rebuild
# - path: ./app
# target: /usr/src/app
# action: sync
version: "3.9"
services:
kwirk-db:
image: mysql:latest
restart: always
ports:
- 3308:3306
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
container_name: kwirk-mysql
volumes:
- ./data:/docker-entrypoint-initdb.d
kwirk-app:
platform: "linux/amd64"
build:
context: .
dockerfile: Dockerfile
args:
NEXT_PUBLIC_CLIENTVAR: "clientvar"
# image: t3-app
depends_on:
- kwirk-db
working_dir: /app
ports:
- 3000:3000
- 35729:35729
environment:
- DATABASE_URL=${DATABASE_URL}
- UPLOADTHING_SECRET=${UPLOADTHING_SECRET}
# - NEXT_PUBLIC_UPLOADTHING_SECRET=${NEXT_PUBLIC_UPLOADTHING_SECRET}
- UPLOADTHING_APP_ID=${UPLOADTHING_APP_ID}
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
- NEXTAUTH_URL=${NEXTAUTH_URL}
# develop:
# watch:
# - path: ./app/package.json
# action: rebuild
# - path: ./app
# target: /usr/src/app
# action: sync
No description
1 Reply
Mango Juicy
Mango Juicy•8mo ago
The error originates from the "kwirk-app" docker container. I don't see node_modules being copied to "runner" stage, so maybe this is the root issue?
Want results from more Discord servers?
Add your server