Skip to content

Commit

Permalink
The docker-compose.yml file is added
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlock28 committed May 30, 2021
1 parent d686e84 commit 28fa987
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Empty file removed Docker-compose.yml
Empty file.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ COPY . .

EXPOSE 4000

CMD ["npm", "start"]
CMD ["npm", "run", "dev"]
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3"

services:
api:
container_name: pizzapp_back
restart: always
build: .
ports:
- "3001:4000"
links:
- mongo
volumes:
- .:/usr/src/app
mongo:
container_name: pizzapp_database
image: mongo
ports:
- "27018:27017"
logging:
driver: none
9 changes: 7 additions & 2 deletions src/database.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
const mongoose = require("mongoose");

const DB =
process.env.NODE_ENV === "development"
? process.env.DATABASE_DOCKER
: process.env.DATABASE;

mongoose
.connect(process.env.DATABASE, {
.connect(DB, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: true,
})
.then(db => console.log("db is connected"))
.then(db => console.log("db is connected to", db.connection.name))
.catch(err => {
console.error(err);
console.error("database connection failed");
Expand Down

0 comments on commit 28fa987

Please sign in to comment.