Skip to content

Instantly share code, notes, and snippets.

@mucaho
Last active April 13, 2020 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mucaho/799c50fab2956cb227b8947e9af82488 to your computer and use it in GitHub Desktop.
Save mucaho/799c50fab2956cb227b8947e9af82488 to your computer and use it in GitHub Desktop.
Example Dockerfile and docker-compose.yml for a node js application with mongo db
version: "3.7"
services:
app:
build: ./app
environment:
- MONGO_URI=mongodb://mongo:27017/app
depends_on:
- "mongo"
command: ["/bin/wait-for.sh", "mongo:27017", "--", "node", "app.js"]
ports:
- "8888:8888"
mongo:
image: "mongo:3"
healthcheck:
test: "if mongo --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'; then exit 0; fi; exit 1;"
start_period: 60s
interval: 60s
timeout: 15s
retries: 5
FROM node:12-alpine
RUN apk add --no-cache tini
RUN apk add --no-cache curl
ADD https://raw.githubusercontent.com/eficode/wait-for/master/wait-for /bin/wait-for.sh
RUN chmod +rx /bin/wait-for.sh
USER node
RUN mkdir -p /home/node/app
WORKDIR /home/node/app
COPY --chown=node:node package*.json ./
ENV NODE_ENV=production
RUN npm ci --only=production
# make sure to .dockerignore all unneeded files
COPY --chown=node:node . .
EXPOSE 8888
HEALTHCHECK --start-period=60s --interval=60s --timeout=15s --retries=5 \
CMD curl -f http://localhost:8888/ || exit 1
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "app.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment