compose-go icon indicating copy to clipboard operation
compose-go copied to clipboard

Added validation for container_name broken with profiles

Open arxeiss opened this issue 1 year ago • 0 comments

Description:

After release docker compose version 2.24.7, especially #585 our docker-compose.yaml file is broken.

We are using profiles to run platform locally in different scenarios. And the profile is used not to run some services, unless they are explicitly specified. Here are scenarios

  • docker compose up - will run whole platform in Docker
  • docker compose up nginx-for-linux pubsub temporal - I'm on Linux machine, all microservices are running in IDE outside docker network, except the ingress and additional tools
  • docker compose up nginx-for-macos pubsub temporal Same as above, but on MacOS

See that container_name is always the same in snippet below. Because we never run nginx, nginx-for-linux and nginx-for-macos together. It worked well for us.

The reason for that is:

  • docker compose up runs all in docker in 1 network
  • In debug mode on Linux we are using network_mode: host, so we can connect to locally runing microservice (outside docker network). Thus we are not using nginx but nginx-for-linux which has different ports in nginx configuration.
  • Similar on MacOS, where nginx has grpc_pass grpc://host.docker.internal:8081; etc.

Suggestion

Would it be possible to validate only services that are really going to run? If I would run docker compose up nginx nginx-for-linux then there are 2 containers with the same name. Or docker compose up --profile local but not otherwise.

Snippet from docker-compose.yaml


services:
    nginx:
        image: nginx
        container_name: ingress
        volumes:
            - ./docker/nginx/conf/nginx.conf:/etc/nginx/conf.d/default.conf:ro

    # ONLY LINUX - https://docs.docker.com/network/host/
    # This one is used only for local development purpose
    # use `docker-compose up nginx-for-linux to run
    nginx-for-linux:
        image: nginx
        # With host network mode the ports are not allowed. All ports are hardcoded to config file
        network_mode: host
        container_name: ingress
        # When profile is specified `docker-compose up` will not start those services, which is what we need here
        profiles:
            - local
        volumes:
            - ./docker/nginx/conf/linux-nginx.conf:/etc/nginx/conf.d/default.conf:ro

    # ONLY macOS
    # This one is used only for local development purpose when running certain services outside of Docker
    # use `docker-compose up nginx-for-local to run
    nginx-for-macos:
        image: nginx
        container_name: ingress
        # When profile is specified `docker-compose up` will not start those services, which is what we need here
        profiles:
            - local
        volumes:
            - ./docker/nginx/conf/macos-nginx.conf:/etc/nginx/conf.d/default.conf:ro

    #Temporal
    temporal:
        image: temporalio/auto-setup:${SERVER_TAG:-1.19.1}
        networks:
            jarvis-network:
        ports:
            - 7233:7233
        volumes:
            - ${DYNAMIC_CONFIG_DIR:-./docker/temporal/config/dynamicconfig}:/etc/temporal/config/dynamicconfig
    ...

arxeiss avatar Mar 19 '24 12:03 arxeiss