colejoffray / Stockify

1 stars 0 forks source link

Add Docker files for easier development/deployment #4

Open nucleardreamer opened 8 months ago

nucleardreamer commented 8 months ago

One common thing for a database driven project is the run mongodb and your project inside Docker (see installing here). In the situation this will be two files, one Dockerfile and one docker-compose.yml. This gives you portability for the database (meaning it's not just installed locally), and replicates what you might deploy to a service like railway, heroku, etc.

A simple Dockerfile would be something like:

FROM node:18-slim

COPY package*.json ./

RUN JOBS=MAX npm install --production && npm cache verify && rm -rf /tmp/*

COPY . ./

CMD ["npm", "start"]

And a docker-compose.yml something like this:

version: "2.1"

services:
  stockify:
    container_name: stockify
    build: .
    ports:
      - 5000:5000
  mongodb:
    image: mongo:latest
    ports:
      - '27017:27017'
    volumes:
      - dbdata:/data/db
volumes:
  dbdata:

Note, this is just an example from memory and not tested, so it may not work right off the bat. Let's chat if you want to learn more about Docker!

rjoffray commented 8 months ago

here is a link to docker docs that discusses docker commit that will allow you to save state of a docker container file system

https://docs.docker.com/engine/reference/commandline/commit/