Skip to content

Commit

Permalink
optimize dockerfile and compose
Browse files Browse the repository at this point in the history
Signed-off-by: Jubayer <[email protected]>
  • Loading branch information
ajshovon committed Oct 21, 2024
1 parent 481d7ec commit a2847bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
14 changes: 5 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use the official Node.js image.
FROM node:18
FROM node:18-slim

# Set the working directory.
WORKDIR /var/www/ims-nest-api-starter
Expand All @@ -9,19 +9,15 @@ ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.s
RUN chmod +x /usr/local/bin/wait-for-it

# Copy package.json and package-lock.json to the working directory.
COPY package.json package-lock.json ./

# Copy all project files to the working directory, excluding those in .dockerignore.
COPY . .

# Copy the Docker-specific environment file.
COPY .env.docker .env
COPY package*.json ./

# Install app dependencies.
RUN npm cache clean --force && rm -rf node_modules && npm install && npm rebuild bcrypt
RUN npm install

# Expose the application port.
EXPOSE 8000

COPY . .

# Set the entrypoint command to wait for the database and then start the application
CMD wait-for-it db:5432 -- npm run start:dev --preserveWatchOutput
15 changes: 4 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
services:
app:
image: ims-nest-api-starter
container_name: ims-nest-api-starter
build:
context: .
dockerfile: Dockerfile
env_file: .env.docker
ports:
- "8000:8000"
volumes:
- .:/var/www/ims-nest-api-starter
- node_modules:/var/www/ims-nest-api-starter/node_modules
- ./src:/var/www/ims-nest-api-starter/src
- ./test:/var/www/ims-nest-api-starter/test
depends_on:
- db
environment:
- DB_HOST=db
- DB_PORT=5432
- DB_NAME=ims_nest
- DB_USERNAME=postgres
- DB_PASSWORD=postgres
restart: unless-stopped

db:
Expand All @@ -33,5 +27,4 @@ services:
- "5432:5432"

volumes:
postgres_data:
node_modules:
postgres_data:

0 comments on commit a2847bd

Please sign in to comment.