Skip to content

Commit 4bd65f8

Browse files
committed
NAS-0: improve docker-compose
1 parent 0763774 commit 4bd65f8

File tree

7 files changed

+12407
-6896
lines changed

7 files changed

+12407
-6896
lines changed

.DS_Store

-6 KB
Binary file not shown.

.env.temp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DATABASE_URL=
2+
HTTP_PORT=
3+
JWT_SECRET=
4+
REDIS_URL=

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ node_modules
1818

1919
# dotenv environment variables file
2020
.env
21-
21+
.env.local
22+
.env.staging
23+
.env.stage
24+
.env.prod
25+
.local.env
26+
.test.env
2227
# Coverage directory used by tools like istanbul
2328
coverage
2429
# nyc test coverage
2530
.nyc_output
26-
2731
# Compiled binary addons (http://nodejs.org/api/addons.html)
2832
build/Release

Dockerfile

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
FROM node:11.5.0-alpine
1+
FROM node:16-alpine as builder
2+
RUN mkdir -p /build
23

4+
COPY ./package.json ./package-lock.json /build/
5+
WORKDIR /build
6+
RUN npm ci
7+
8+
# Bundle app source
9+
COPY . /build
10+
11+
FROM node:16-alpine
12+
# user with username node is provided from the official node image
13+
ENV user node
314
# Run the image as a non-root user
4-
RUN adduser -S api
5-
USER api
15+
USER $user
616

717
# Create app directory
8-
RUN mkdir -p /home/api/app
9-
WORKDIR /home/api/app
18+
RUN mkdir -p /home/$user/src
19+
WORKDIR /home/$user/src
1020

11-
# Install app dependencies
12-
COPY --chown=api:nogroup package.json package-lock.json /home/api/app
13-
RUN npm install
21+
COPY --from=builder /build ./
1422

1523
EXPOSE 5555
16-
CMD [ "npm", "start" ]
24+
25+
ENV NODE_ENV production
26+
27+
CMD ["npm", "start"]

docker-compose.yml

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1-
version: '3.4'
1+
version: '3.9'
22
services:
3-
web:
4-
build: .
5-
ports:
6-
- "5555:5555"
7-
env_file: .env
8-
depends_on:
9-
- db
10-
volumes:
11-
- .:/usr/src/api
12-
db:
13-
image: mongo:latest
14-
ports:
15-
- "27017:27017"
16-
env_file: .env
3+
api-showcase:
4+
build:
5+
context: .
6+
container_name: nodejs-api-showcase
7+
ports:
8+
- "5555:5555"
9+
env_file: .env
10+
environment:
11+
- DATABASE_URL=mongodb://db:27017/nodejsshowcase
12+
depends_on:
13+
- db
14+
- redis
15+
volumes:
16+
- .:/home/nodejs/src
17+
db:
18+
image: mongo:latest
19+
ports:
20+
- "27017:27017"
21+
volumes:
22+
- mongodb:/data/db
23+
env_file: .env
24+
redis:
25+
image: redis:alpine
26+
command: ["redis-server", "--bind", "redis", "--port", "6379"]
27+
container_name: redis
28+
ports:
29+
- "6379:6379"
30+
restart:
31+
always
32+
volumes:
33+
mongodb:

0 commit comments

Comments
 (0)