如何使用分子器 运行 独立 docker 图像而不是使用 "compose up"?
How to running independently docker images with moleculer instead using "compose up"?
我有这个 docker-compose.yaml。它定义了 1 个服务 public API 和 4 个服务(复制),每个服务都有另外两个微服务(一个接收事件,另一个将信息保存到 mongo)。当我执行“docker-compose up”时,这非常有效。但我想 运行 每张图片都带有“docker 运行”。
version: "3.3"
services:
api:
build:
context: .
image: monitor-log-public
#container_name: monitor-log-public
env_file: docker-compose.env
environment:
SERVICES: api
PORT: 3000
#depends_on:
# - redis
labels:
- "traefik.enable=false"
- "traefik.http.routers.api-gw.rule=PathPrefix(`/`)"
- "traefik.http.services.api-gw.loadbalancer.server.port=3000"
networks:
- internal
ports:
- 3000:3000
monitor-1:
build:
context: .
image: monitor-log-monitor-1
#container_name: monitor-log-logger
env_file: docker-compose.env
environment:
SERVICES: monitor,logs.db
#depends_on:
# - redis
networks:
- internal
monitor-2:
build:
context: .
image: monitor-log-monitor-2
#container_name: monitor-log-logger
env_file: docker-compose.env
environment:
SERVICES: monitor,logs.db
#depends_on:
# - redis
networks:
- internal
monitor-3:
build:
context: .
image: monitor-log-monitor-3
#container_name: monitor-log-logger
env_file: docker-compose.env
environment:
SERVICES: monitor,logs.db
#depends_on:
# - redis
networks:
- internal
monitor-4:
build:
context: .
image: monitor-log-monitor-4
#container_name: monitor-log-logger
env_file: docker-compose.env
environment:
SERVICES: monitor,logs.db
#depends_on:
# - redis
networks:
- internal
#redis:
# image: redis:alpine
# networks:
# - internal
networks:
internal:
internal: false
volumes:
data:
当我执行“编写 运行 monitor-log-public”时,执行会因任何原因而关闭。
c:\temp\monitor-log-image>docker run monitor-log-monitor-1
[2021-02-22T08:51:42.449Z] INFO b304e268d414-1/BROKER: Moleculer v0.14.12 is starting...
[2021-02-22T08:51:42.451Z] INFO b304e268d414-1/BROKER: Namespace: <not defined>
[2021-02-22T08:51:42.451Z] INFO b304e268d414-1/BROKER: Node ID: b304e268d414-1
[2021-02-22T08:51:42.452Z] INFO b304e268d414-1/REGISTRY: Strategy: RoundRobinStrategy
[2021-02-22T08:51:42.452Z] INFO b304e268d414-1/REGISTRY: Discoverer: LocalDiscoverer
[2021-02-22T08:51:42.453Z] INFO b304e268d414-1/BROKER: Serializer: JSONSerializer
[2021-02-22T08:51:42.458Z] INFO b304e268d414-1/BROKER: Validator: FastestValidator
[2021-02-22T08:51:42.459Z] INFO b304e268d414-1/BROKER: Registered 13 internal middleware(s).
[2021-02-22T08:51:42.471Z] INFO b304e268d414-1/REGISTRY: '$node' service is registered.
[2021-02-22T08:51:42.472Z] INFO b304e268d414-1/$NODE: Service '$node' started.
[2021-02-22T08:51:42.473Z] INFO b304e268d414-1/BROKER: ✔ ServiceBroker with 1 service(s) is started successfully in 6ms.
[2021-02-22T08:51:42.474Z] INFO b304e268d414-1/$NODE: Service '$node' stopped.
[2021-02-22T08:51:42.474Z] INFO b304e268d414-1/BROKER: ServiceBroker is stopped. Good bye.
我看到这个执行不知道需要加载“api”服务,但是那个定义在docker-compose.yaml,为什么图像没有读那个??
只需在 docker run
中设置环境变量
例如
docker run -e SERVICES="monitor,logs.db" monitor-log-monitor-1
我有这个 docker-compose.yaml。它定义了 1 个服务 public API 和 4 个服务(复制),每个服务都有另外两个微服务(一个接收事件,另一个将信息保存到 mongo)。当我执行“docker-compose up”时,这非常有效。但我想 运行 每张图片都带有“docker 运行”。
version: "3.3"
services:
api:
build:
context: .
image: monitor-log-public
#container_name: monitor-log-public
env_file: docker-compose.env
environment:
SERVICES: api
PORT: 3000
#depends_on:
# - redis
labels:
- "traefik.enable=false"
- "traefik.http.routers.api-gw.rule=PathPrefix(`/`)"
- "traefik.http.services.api-gw.loadbalancer.server.port=3000"
networks:
- internal
ports:
- 3000:3000
monitor-1:
build:
context: .
image: monitor-log-monitor-1
#container_name: monitor-log-logger
env_file: docker-compose.env
environment:
SERVICES: monitor,logs.db
#depends_on:
# - redis
networks:
- internal
monitor-2:
build:
context: .
image: monitor-log-monitor-2
#container_name: monitor-log-logger
env_file: docker-compose.env
environment:
SERVICES: monitor,logs.db
#depends_on:
# - redis
networks:
- internal
monitor-3:
build:
context: .
image: monitor-log-monitor-3
#container_name: monitor-log-logger
env_file: docker-compose.env
environment:
SERVICES: monitor,logs.db
#depends_on:
# - redis
networks:
- internal
monitor-4:
build:
context: .
image: monitor-log-monitor-4
#container_name: monitor-log-logger
env_file: docker-compose.env
environment:
SERVICES: monitor,logs.db
#depends_on:
# - redis
networks:
- internal
#redis:
# image: redis:alpine
# networks:
# - internal
networks:
internal:
internal: false
volumes:
data:
当我执行“编写 运行 monitor-log-public”时,执行会因任何原因而关闭。
c:\temp\monitor-log-image>docker run monitor-log-monitor-1
[2021-02-22T08:51:42.449Z] INFO b304e268d414-1/BROKER: Moleculer v0.14.12 is starting...
[2021-02-22T08:51:42.451Z] INFO b304e268d414-1/BROKER: Namespace: <not defined>
[2021-02-22T08:51:42.451Z] INFO b304e268d414-1/BROKER: Node ID: b304e268d414-1
[2021-02-22T08:51:42.452Z] INFO b304e268d414-1/REGISTRY: Strategy: RoundRobinStrategy
[2021-02-22T08:51:42.452Z] INFO b304e268d414-1/REGISTRY: Discoverer: LocalDiscoverer
[2021-02-22T08:51:42.453Z] INFO b304e268d414-1/BROKER: Serializer: JSONSerializer
[2021-02-22T08:51:42.458Z] INFO b304e268d414-1/BROKER: Validator: FastestValidator
[2021-02-22T08:51:42.459Z] INFO b304e268d414-1/BROKER: Registered 13 internal middleware(s).
[2021-02-22T08:51:42.471Z] INFO b304e268d414-1/REGISTRY: '$node' service is registered.
[2021-02-22T08:51:42.472Z] INFO b304e268d414-1/$NODE: Service '$node' started.
[2021-02-22T08:51:42.473Z] INFO b304e268d414-1/BROKER: ✔ ServiceBroker with 1 service(s) is started successfully in 6ms.
[2021-02-22T08:51:42.474Z] INFO b304e268d414-1/$NODE: Service '$node' stopped.
[2021-02-22T08:51:42.474Z] INFO b304e268d414-1/BROKER: ServiceBroker is stopped. Good bye.
我看到这个执行不知道需要加载“api”服务,但是那个定义在docker-compose.yaml,为什么图像没有读那个??
只需在 docker run
中设置环境变量
例如
docker run -e SERVICES="monitor,logs.db" monitor-log-monitor-1