coollabsio / coolify

An open-source & self-hostable Heroku / Netlify / Vercel alternative.
https://coolify.io
Apache License 2.0
31.05k stars 1.57k forks source link

[Bug]: container_name prevents replication. #2131

Open chrisbecke opened 4 months ago

chrisbecke commented 4 months ago

Description

It is not possible to deploy Docker compose files with "replicas:" other than 1.

Minimal Reproduction (if possible, example repository)

Create a Docker Compose resource and attach the following compose.yaml

services:
  my:
    image: 'nginx:latest'
    deploy:
      replicas: 3

Exception or Error

Saved configuration files to /data/coolify/services/iokgo8w.
Creating Docker network.
Starting service.
Pulling images.
services.deploy.replicas: can't set container_name and my as container name must be unique: invalid compose project

Version

v4.0.0-beta.270

Aniketh999 commented 4 months ago

To resolve this issue, you need to ensure that each replica has a unique container name. You can achieve this by using the container_name option in your service configuration. Here's an example of how you can modify your Docker Compose file:

services: my: image: 'nginx:latest' deploy: replicas: 3 container_name: my_container_1 deploy: replicas: 3 container_name: my_container_2 deploy: replicas: 3 container_name: my_container_3

josselinlbe commented 2 months ago

Interested!

vanWittlaer commented 4 days ago

To resolve this issue, you need to ensure that each replica has a unique container name. You can achieve this by using the container_name option in your service configuration. Here's an example of how you can modify your Docker Compose file:

services: my: image: 'nginx:latest' deploy: replicas: 3 container_name: my_container_1 deploy: replicas: 3 container_name: my_container_2 deploy: replicas: 3 container_name: my_container_3

@Aniketh999 Sorry I somehow can't get this to work with your answer. Complains about duplicate "deploy:" What am I getting wrong? Would you mind posting a properly formatted example? Thanks!

Thytu commented 3 days ago

Would be interesting to see if the same happens with a raw Docker Compose

vanWittlaer commented 9 hours ago

The problem is inherent to coolify generating the container names and not knowing about replicas. So rather a feature than a bug :-).

I can get by with this workaround:

services:
    worker-1: &worker
        image: vanwittlaer/some-image:latest
        restart: unless-stopped
        ...
    worker-2: *worker
    worker-3: *worker
Thytu commented 7 hours ago

The problem is inherent to coolify generating the container names and not knowing about replicas. So rather a feature than a bug :-).

I can get by with this workaround:

services:
    worker-1: &worker
        image: vanwittlaer/some-image:latest
        restart: unless-stopped
        ...
    worker-2: *worker
    worker-3: *worker

Smart! Unfortunately it might only solve half the problem, not having real replica prevents the rolling update features, meaning the service will experience down-time at each update.