diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..e49ceee7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.env +.git +.vscode +.*ignore +docker-compose*.yml +node_modules +*.md \ No newline at end of file diff --git a/.env b/.env index 1cbbc6de..783f542b 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ PORT=8765 -DB_HOST=localhost +DB_HOST=db DB_USERNAME=root DB_PASSWORD=example DB_NAME=fake_store diff --git a/.gitignore b/.gitignore index 336a5fe3..f0a5a962 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules package-lock.json .vscode app.js -Procfile \ No newline at end of file +Procfile +mongo_data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..02509277 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:17 + +WORKDIR /usr/src/app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +EXPOSE $PORT + +CMD [ "node", "server.js" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..f48a8cbf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +version: '3.1' + +services: + app: + build: . + env_file: + - .env + ports: + - "${PORT}:${PORT}" + depends_on: + - db + db: + image: mongo + restart: always + volumes: + - ./mongo_data:/data/db + env_file: + - .env + environment: + MONGO_INITDB_ROOT_USERNAME: ${DB_USERNAME?MongoDB username} + MONGO_INITDB_ROOT_PASSWORD: ${DB_PASSWORD?MongoDB password} \ No newline at end of file