[英]How can I run NodeJS in Docker with MongoDB and RabbitMQ?
How can I run NodeJs in Docker and Connect it with MongoDB and RabbitMQ?如何在 Docker 中运行 NodeJ 并将其与 MongoDB 和 RabbitMQ 连接? Do I need to run it in with
docker-compose
?我需要用
docker-compose
运行它吗?
And also I need 2 environment而且我还需要2个环境
nodemon
.nodemon
应用程序。node app.js
node app.js
I found this docker-compose
yml, but I can not understand how to connect it from nodejs我找到了这个
docker-compose
yml,但我不明白如何从 nodejs 连接它
services:
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: rabbitmq
environment:
RABBITMQ_ERLANG_COOKIE: ${RABBITMQ_ERLANG_COOKIE}
RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
After a few days, I found this repo with RabbitMQ, MongoDB.几天后,我找到了这个带有 RabbitMQ、MongoDB 的仓库。 Also here you can find Mongo-express, where you can work with Mongo directly.
您还可以在这里找到 Mongo-express,您可以在其中直接使用 Mongo。
https://github.com/stdakov/docker-rabbit-mongo https://github.com/stdakov/docker-rabbit-mongo
Installation:安装:
git clone https://github.com/stdakov/docker-rabbit-mongo.git
cd docker-rabbit-mongo/
docker-compose up -d
No, you do not need to run it with docker-compose
.不,您不需要使用
docker-compose
运行它。
I would recommend creating the following files:我建议创建以下文件:
The Dockerfile.dev would look something like this: Dockerfile.dev 看起来像这样:
FROM node:10-alpine
ENV PORT 8080
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install -g nodemon
RUN npm install
ENTRYPOINT ["nodemon", "/usr/src/app/server.js"]
The command to build the image: docker build. -t node-app -f Dockerfile.dev
构建镜像的命令:
docker build. -t node-app -f Dockerfile.dev
docker build. -t node-app -f Dockerfile.dev
The command to run the image: docker run --rm -it -p 8080:8080 --network my-node-net -v "${PWD}:/usr/src/app" node-app
docker build. -t node-app -f Dockerfile.dev
运行镜像的命令: docker run --rm -it -p 8080:8080 --network my-node-net -v "${PWD}:/usr/src/app" node-app
Check out this example I saw: https://github.com/kelda/node-todo看看我看到的这个例子: https://github.com/kelda/node-todo
You also need to implement rmq and mongo client connections and run the official images inside the same network as the node-app
您还需要实现 rmq 和 mongo 客户端连接,并在与 node-app 相同的网络内运行官方图像
All compose options can be translated into docker run commands
所有 compose 选项都可以翻译成 docker 运行命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.