Skip to content

Instantly share code, notes, and snippets.

@K-Mistele
Last active March 29, 2024 19:11
Show Gist options
  • Save K-Mistele/21240550c557e0aaf7fb8e51c5290a73 to your computer and use it in GitHub Desktop.
Save K-Mistele/21240550c557e0aaf7fb8e51c5290a73 to your computer and use it in GitHub Desktop.
Trivially Dockerizing a Next.js Application
FROM node:18
WORKDIR /opt/app
COPY package*.json ./
RUN npm install
# use --build-arg=example_api_key=1234 to set the API_KEY env var. repeat as necessary
# in your github action or other CI/CD, set the arguments from your secrets store.
ARG example_api_key
ARG example_public_variable
ENV API_KEY $example_api_key
ENV NEXT_PUBLIC_ENV_VARIABLE=$example_public_variable
# Copy the current directory contents into the container at /app
COPY . .
# Build the Next.js app
RUN npm run build
# Expose port 3000 for the app
EXPOSE 3000
# Start the app
CMD ["npm", "run", "start"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment