Last active
July 28, 2024 08:09
-
-
Save kennethnwc/efc81d448a6381f07fd42b4305f12f68 to your computer and use it in GitHub Desktop.
My docker-compose with nextjs and nginx
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
.next/ | |
node_modules/ | |
Dockerfile | |
yarn-error.log | |
.dockerignore | |
.git | |
.gitignore |
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
image: docker | |
services: | |
- docker:dind | |
stages: | |
- test | |
- deploy | |
test: | |
stage: test | |
only: | |
- staging | |
script: | |
- echo It should be running some test | |
tags: | |
- staging | |
step-deploy-staging: | |
stage: deploy | |
only: | |
- staging | |
variables: | |
API_URL: "" | |
GOOGLE_KEY: "ABCD" | |
NEXT_APP_VERSION: "0.0.13" | |
script: | |
# - sudo docker image prune -f | |
# - docker volume prune -f | |
- docker-compose build | |
- docker-compose down | |
- docker-compose up -d | |
tags: | |
- staging | |
environment: staging | |
step-deploy-prod: | |
stage: deploy | |
only: | |
- production | |
variables: | |
API_URL: "" | |
script: | |
- sudo docker image prune -f | |
- docker-compose build --no-cache | |
- docker-compose up -d | |
environment: production |
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
version: "3.8" | |
services: | |
nextjs: | |
ports: | |
- "3000:3000" | |
build: | |
context: nextapp | |
dockerfile: Dockerfile.dev | |
volumes: | |
- ./nextapp:/app | |
- nextjs-dev-node_modules:/app/node_modules | |
- nextjs-dev-next:/app/.next | |
restart: always | |
frontend: | |
image: nginx:latest | |
volumes: | |
- ./nginx/nginx.conf:/etc/nginx/nginx.conf | |
- ./nginx/conf.d:/etc/nginx/conf.d | |
ports: | |
- "80:80" | |
depends_on: | |
- nextjs | |
restart: always | |
volumes: | |
nextjs-dev-node_modules: | |
nextjs-dev-next: |
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
version: "3.8" | |
services: | |
nextjs: | |
image: kennethnwc/nextapp:${NEXT_APP_VERSION} | |
ports: | |
- "3000:3000" | |
build: | |
context: nextapp | |
dockerfile: Dockerfile | |
target: prod | |
args: | |
NEXT_PUBLIC_GOOGLE_KEY: ${GOOGLE_KEY} | |
NEXT_PUBLIC_APP_VERSION: ${NEXT_APP_VERSION} | |
volumes: | |
- /app/node_modules | |
- /app/.next | |
restart: always | |
environment: | |
- API_URL=${API_URL} | |
- GOOGLE_KEY=${GOOGLE_KEY} | |
frontend: | |
image: nginx:latest | |
volumes: | |
- ./nginx/nginx.conf:/etc/nginx/nginx.conf | |
- ./nginx/conf.d:/etc/nginx/conf.d | |
ports: | |
- "80:80" | |
depends_on: | |
- nextjs | |
restart: always |
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:14.15-alpine as base | |
RUN mkdir /app | |
WORKDIR /app | |
COPY package*.json ./ | |
COPY yarn.lock ./ | |
FROM base as pre-prod | |
COPY . . | |
RUN yarn install --frozen-lockfile | |
ARG NEXT_PUBLIC_GOOGLE_KEY | |
ARG NEXT_PUBLIC_APP_VERSION | |
ENV NEXT_PUBLIC_GOOGLE_KEY=${NEXT_PUBLIC_GOOGLE_KEY} | |
ENV NEXT_PUBLIC_APP_VERSION=${NEXT_PUBLIC_APP_VERSION} | |
RUN yarn build | |
FROM node:14.15-alpine as prod | |
RUN mkdir /app | |
WORKDIR /app | |
COPY --from=pre-prod /app/public ./public | |
COPY --from=pre-prod /app/.next ./.next | |
COPY --from=pre-prod /app/node_modules ./node_modules | |
EXPOSE 3000 | |
CMD ["node_modules/.bin/next", "start"] |
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:14.5.0 as dev | |
RUN mkdir /app | |
WORKDIR /app | |
COPY package*.json ./ | |
COPY yarn.lock ./ | |
RUN yarn | |
EXPOSE 3000 | |
CMD ["yarn" , "dev"] |
RUN mkdir /app
WORKDIR /app
why mkdir when workdir will create it?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This setup i used was long long time ago. I am not sure it helps. Here the nginx conf i got.
`resolver 10.xxx.x.x;
server {
listen 80;
# server_name _;
}
}`
I have no idea how this works right now. lol