moleculerjs / moleculer-template-project

:mortar_board: Common project template for Moleculer-based projects
MIT License
21 stars 21 forks source link

Error in docker-compose.yml after #5 #6

Closed AndreMaz closed 5 years ago

AndreMaz commented 5 years ago

Hey @intech . It seems that PR https://github.com/moleculerjs/moleculer-template-project/pull/5 has a slight problem in docker-compose.yml. For some reason it generates entries like this:

networks:
  internal:

Current:

version: "3.7"

services:
  api:
    build:
      context: .
    image: moleculer-demo
    container_name: moleculer-demo-api
    env_file: docker-compose.env
    environment:
      SERVICES: api
      PORT: 3000
    depends_on:
      - nats
    labels:
      - "traefik.enable=true"
      - "traefik.backend=api"
      - "traefik.port=3000"
      - "traefik.frontend.entryPoints=http"
      - "traefik.frontend.rule=PathPrefix:/"
    networks:
      - internal

  greeter:
    build:
      context: .
    image: moleculer-demo
    container_name: moleculer-demo-greeter
    env_file: docker-compose.env
    environment:
      SERVICES: greeter
    labels:
      - "traefik.enable=false"
    depends_on:
      - nats

  networks:
    - internal

  nats:
    image: nats
    labels:
      - "traefik.enable=false"
    networks:
      - internal

  traefik:
    image: traefik
    container_name: traefik
    command:
      - "--api"
      - "--docker"
      - "--docker.watch"
    labels:
      - "traefik.enable=true"
      - "traefik.backend=traefik"
      - "traefik.port=8080"
    ports:
      - 3000:80
      - 3001:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /dev/null:/traefik.toml
    networks:
      - internal
      - default

networks:
  internal:

Running npm run dc:up produces the following error:

ERROR: In file '.\docker-compose.yml', service 'networks' must be a mapping not an array.

To get things working again I had to remove all references about network

version: "3.7"

services:
  api:
    build:
      context: .
    image: moleculer-demo
    container_name: moleculer-demo-api
    env_file: docker-compose.env
    environment:
      SERVICES: api
      PORT: 3000
    depends_on:
      - nats
    labels:
      - "traefik.enable=true"
      - "traefik.backend=api"
      - "traefik.port=3000"
      - "traefik.frontend.entryPoints=http"
      - "traefik.frontend.rule=PathPrefix:/"

  greeter:
    build:
      context: .
    image: moleculer-demo
    container_name: moleculer-demo-greeter
    env_file: docker-compose.env
    environment:
      SERVICES: greeter
    labels:
      - "traefik.enable=false"
    depends_on:
      - nats

  nats:
    image: nats
    labels:
      - "traefik.enable=false"

  traefik:
    image: traefik
    container_name: traefik
    command:
      - "--api"
      - "--docker"
      - "--docker.watch"
    labels:
      - "traefik.enable=true"
      - "traefik.backend=traefik"
      - "traefik.port=8080"
    ports:
      - 3000:80
      - 3001:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /dev/null:/traefik.toml

Can you please fix it?

AndreMaz commented 5 years ago

Steps to reproduce image

intech commented 5 years ago

@AndreMaz Now I’ll see what can be a mistake, I checked it several times before accepting @icebob.

intech commented 5 years ago

@AndreMaz sorry, I don’t understand how I didn’t encounter a syntactic error during the check :( Check again, now you will not have an error with the network array.

Снимок экрана от 2019-07-27 05-27-02

Сompletely remove the network will be the wrong decision in terms of the architecture of the docker. I understand that this is the basic environment and is intended for tests, but in practice it will all be used in production, where the standard Docker's overlay network will lower the throughput and there will be some security aspects in relation to other containers.

AndreMaz commented 5 years ago

Hey @intech. Thanks for quick answer and your help. Still, something isn't right. Now I'm getting this:

ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
AndreMaz commented 5 years ago

Sorry. I've tested on Linux machine (LTS 18.04) that had old versions docker-compose version 1.17.1 and docker version 17.05.0-ce... It seems that version: "3.7" of docker-compose is not supported. Max supported version is version: "3.5".

Do you think that it's best to change to 3.5 to avoid any potential problems like I've had?


Update: After updating to Docker version 19.03.1 and docker-compose version 1.24.1 things are working with version: "3.7". However, I think that we should go with 3.5 or lower for compatibility reasons

intech commented 5 years ago

@AndreMaz change version on 3.2 this minimal my recommendation, it's works on docker engine version 17.04.0+

AndreMaz commented 5 years ago

Thanks for your expertise @intech