Nuxt ENV not working in docker container
Hello!
I am working on a Nuxt3 project and I would like to have a docker container running it, but I'm facing some issues.
When the image is built and the container is created, the ENV variables I pass through the docker compose are not being passed to Nuxt, I can confirm this through some console logs.
What could I be doing wrong?
Dockerfile:
Docker compose:
I am working on a Nuxt3 project and I would like to have a docker container running it, but I'm facing some issues.
When the image is built and the container is created, the ENV variables I pass through the docker compose are not being passed to Nuxt, I can confirm this through some console logs.
What could I be doing wrong?
Dockerfile:
# Use an official node image as the base image
FROM oven/bun:1 as builder
WORKDIR /usr/src/app
# Set the working directory
WORKDIR /app
# Copy package.json
COPY package*.json ./
# Install dependencies
RUN bun i
# Copy the rest of the application files
COPY . .
# Build the application
RUN bun run build
# Use a smaller image for the production environment
FROM node:22.3.0-alpine3.20
# Set the working directory
WORKDIR /app
# Copy only the necessary files for running the application
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.output ./.output
COPY --from=builder /app/package*.json ./
# Expose the port the app runs on
EXPOSE 3000
# Command to run the application
CMD ["node", ".output/server/index.mjs"]# Use an official node image as the base image
FROM oven/bun:1 as builder
WORKDIR /usr/src/app
# Set the working directory
WORKDIR /app
# Copy package.json
COPY package*.json ./
# Install dependencies
RUN bun i
# Copy the rest of the application files
COPY . .
# Build the application
RUN bun run build
# Use a smaller image for the production environment
FROM node:22.3.0-alpine3.20
# Set the working directory
WORKDIR /app
# Copy only the necessary files for running the application
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.output ./.output
COPY --from=builder /app/package*.json ./
# Expose the port the app runs on
EXPOSE 3000
# Command to run the application
CMD ["node", ".output/server/index.mjs"]Docker compose:
services:
db:
image: postgres:15
container_name: 'postgres_db'
environment:
POSTGRES_DB: spenser
POSTGRES_USER: admin
POSTGRES_PASSWORD: 1234
ports:
- 5432:5432
app:
build: .
container_name: 'spenser'
ports:
- 3000:3000
environment:
JWT_SECRET: changeme
DB_NAME: spenser
DB_HOST: db
DB_USER: admin
DB_PASSWORD: 1234
DB_PORT: 5432
depends_on:
- dbservices:
db:
image: postgres:15
container_name: 'postgres_db'
environment:
POSTGRES_DB: spenser
POSTGRES_USER: admin
POSTGRES_PASSWORD: 1234
ports:
- 5432:5432
app:
build: .
container_name: 'spenser'
ports:
- 3000:3000
environment:
JWT_SECRET: changeme
DB_NAME: spenser
DB_HOST: db
DB_USER: admin
DB_PASSWORD: 1234
DB_PORT: 5432
depends_on:
- db