Last active
March 29, 2024 19:11
-
-
Save K-Mistele/21240550c557e0aaf7fb8e51c5290a73 to your computer and use it in GitHub Desktop.
Trivially Dockerizing a Next.js Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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