skip to Main Content

I have got this docker-compose.yaml. It defines 1 service with the public API and 4 services (replicated) with another two microservices each one (one receives events and another one saves info to mongo). This works perfectly when i do "docker-compose up". But I want to run each images with "docker run".

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:

When I do "compose run monitor-log-public", the execution closes with any reason.

c:tempmonitor-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.

I can see that this execution does not know that needs to load "api" service, but that is defined in the docker-compose.yaml, why the image does not read that??

2

Answers


  1. Just set the env vars in docker run, as well

    E.g.

    docker run -e SERVICES="monitor,logs.db" monitor-log-monitor-1
    
    Login or Signup to reply.
  2. Just use docker-compose’s options:

    docker-compose up <your_service_name>

    For example:

    docker-compose up monitor-1

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search