Skip to content

Commit

Permalink
feat: add local docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
dillionverma committed Mar 18, 2024
1 parent fc351bd commit 3db8745
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
32 changes: 32 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM node:20-alpine

WORKDIR /app

# 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 corepack enable pnpm && pnpm i; \
# Allow install without lockfile, so example works even without Node.js installed locally
else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \
fi

COPY src ./src
COPY public ./public
COPY next.config.js .
COPY tsconfig.json .

# Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry
# Uncomment the following line to disable telemetry at run time
# ENV NEXT_TELEMETRY_DISABLED 1

# Note: Don't expose ports here, Compose will handle that for us

# Start Next.js in development mode based on the preferred package manager
CMD \
if [ -f yarn.lock ]; then yarn dev; \
elif [ -f package-lock.json ]; then npm run dev; \
elif [ -f pnpm-lock.yaml ]; then pnpm dev; \
else npm run dev; \
fi
40 changes: 32 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,44 @@ version: "3.7"
# docker-compose up -d
#

# https://github.com/vercel/next.js/blob/canary/examples/with-docker-compose/docker-compose.dev.yml

services:
default_database:
web:
build:
context: .
dockerfile: dev.Dockerfile
volumes:
- ./src:/app/src
- ./public:/app/public
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres
env_file:
- .env.local
restart: always


database:
restart: unless-stopped
image: postgres:latest
volumes:
- default_database_data:/var/lib/postgresql/data
- database_data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${DEFAULT_DATABASE_DB}
- POSTGRES_USER=${DEFAULT_DATABASE_USER}
- POSTGRES_PASSWORD=${DEFAULT_DATABASE_PASSWORD}
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
env_file:
- .env
- .env.local
ports:
- "${DEFAULT_DATABASE_PORT}:5432"
- "5432:5432"
networks:
- my_network

volumes:
default_database_data:
database_data:

networks:
my_network:
external: true

0 comments on commit 3db8745

Please sign in to comment.