Adding docker support

This commit is contained in:
Adolfo Reyna
2024-10-18 11:59:15 -04:00
parent e52c379a55
commit aac7080f7f
5 changed files with 55 additions and 3 deletions

5
.dockerignore Normal file
View File

@@ -0,0 +1,5 @@
.git
.gitignore
node_modules
logs
dump

4
.gitignore vendored
View File

@@ -6,6 +6,10 @@ yarn-debug.log*
yarn-error.log* yarn-error.log*
lerna-debug.log* lerna-debug.log*
# Dumps
dump
# Diagnostic reports (https://nodejs.org/api/report.html) # Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

View File

@@ -8,10 +8,12 @@ RUN apk add --no-cache python3 make g++
WORKDIR /app WORKDIR /app
# Copy package.json and package-lock.json to the working directory # Copy package.json and package-lock.json to the working directory
COPY package*.json ./ COPY ["package.json", "package-lock.json", "./"]
# Install dependencies # Install dependencies
RUN npm install RUN npm install
RUN npm rebuild bcrypt
RUN npm install nodemon -g
# Copy the rest of the application source code # Copy the rest of the application source code
COPY . . COPY . .
@@ -20,7 +22,7 @@ COPY . .
EXPOSE 3001 EXPOSE 3001
# Command to run your app # Command to run your app
CMD ["npm", "start"] CMD ["nodemon"]
# sudo docker build -t emi-backend . # sudo docker build -t emi-backend .
# sudo docker run -d -p 4000:5000 -e PORT=5000 emi-backend # sudo docker run -d -p 4000:5000 -e PORT=5000 emi-backend

38
docker-compose.yml Normal file
View File

@@ -0,0 +1,38 @@
version: '3.8'
networks:
emi-network:
driver: bridge
services:
app:
build:
context: .
ports:
- '3001:3001'
environment:
- MONGO_URL=mongodb://mongo:27017/testdb
- PORT=3001
volumes:
- .:/app
- '/app/node_modules'
depends_on:
- mongo
command: nodemon
networks:
- emi-network
mongo:
image: mongo:latest
ports:
- '27017:27017'
networks:
- emi-network
volumes:
- mongodbdata:/data/db
- ./dump:/dump
#entrypoint: mongodump ${MONGO_URL} && mongorestore --db EMI_SOCIAL dump/EMI_SOCIAL/ && mongod
volumes:
mongodbdata:
driver: local # This ensures the volume is created

View File

@@ -5,7 +5,10 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js" "start": "node index.js",
"docker": "docker compose up -d",
"docker_restore": "docker-compose exec mongo mongorestore --db EMI_SOCIAL /dump/EMI_SOCIAL/",
"docker_dump": "docker-compose exec mongo mongodump --uri ${MONGO_URL} --out /dump"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",