我目前正在按照微服务架构使用NestJS构建应用程序。并使用NATS作为消息传递系统。它在我的本地机器上运行良好,但我无法对 NATS 服务器进行 docker 化。
我的项目的文件夹结构:
├─── services/
├─── nats/
| Dockerfile
├─── client/
| ...
| ...
| .dockerignore
| Dockerfile
└─── docker-compose.yml
现在,Dockerfile
内部nats/
文件夹描述如下:
FROM nats:2.1.9
EXPOSE 4222
CMD [ "nats-server" ]
Dockerfile
里面client/
的文件夹描述为:
FROM node:12
WORKDIR /myProject/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8081
CMD [ "node", "dist/main" ]
而且docker-compose.yml
是:
version: '3'
services:
nats-server:
image: nats:2.1.9
restart: always
build: ./nats
ports:
- 4222:4222
client-service:
build: ./client
volumes:
- ./client:/myProject/src/app
depends_on:
- nats-server
environment:
NODE_ENV: development
ports:
- 8081:3000
我已经运行命令sudo docker-compose build并没有发现错误,然后运行命令sudo docker-compose up并发现以下错误:
Recreating services_nats-server_1 ... done
Recreating services_client-service_1 ... done
Attaching to services_nats-server_1, services_client-service_1
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
services_nats-server_1 exited with code 1
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [NestFactory] Starting Nest application...
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] AppModule dependencies initialized +41ms
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] MongooseModule dependencies initialized +1ms
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] ClientsModule dependencies initialized +1ms
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] ClientsModule dependencies initialized +0ms
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] ConfigHostModule dependencies initialized +1ms
client-service_1 | [Nest] 1 - 12/03/2020, 4:44:34 PM [InstanceLoader] ConfigModule dependencies initialized +1ms
services_nats-server_1 exited with code 1
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
nats-server_1 | nats-server: unrecognized command: "nats-server_1"
客户端服务 Dockerfile 没有问题,因为它取决于 nats-server 尝试首先运行它。谁能帮我解决问题?
我要感谢您的时间和考虑。