我试图在本地运行节点,但在容器中运行mongoDB,只是找不到最佳的方法。
是否应该在api目录中运行命令并启动npm?
我正在尝试使用docker-compose up
这是我的文件:
docker-compose.yml
/api
Dockerfile
package.json
/db
这是docker-compose.yml
version: '3'
services:
api:
container_name: fl_api
command: cd api && npm start
ports:
- "3002:3002"
environment:
DB_PORT: "27017"
DB_HOST: mongo
PORT: "3002"
networks:
- api_net
mongo:
container_name : fl_mongodb
image: mongo:4.0
volumes:
- ./db/mong-vol:/data/db
networks:
- api_net
expose:
- "27017"
healthcheck:
test: echo 'db.stats().ok' | mongo localhost:27017/zenbrain --quiet
interval: 5s
timeout: 5s
retries: 12
networks:
api_net:
driver: bridge
这是api/Dockerfile
FROM node:6
WORKDIR /food-license-backend
COPY package.json /food-license-backend
RUN npm install
COPY . /food-license-backend
EXPOSE 3002
CMD ["npm", "run", "start"]