Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Network errors between containers in preview builds #4712

Closed
tm1000 opened this issue Dec 31, 2024 · 2 comments
Closed

[Bug]: Network errors between containers in preview builds #4712

tm1000 opened this issue Dec 31, 2024 · 2 comments

Comments

@tm1000
Copy link

tm1000 commented Dec 31, 2024

Error Message and Logs

Preview deployments using Build Pack Docker Compose have broken networking when using the service names directly. The service names do work on the 'primary' app (non preview) but there are network resolution issues when using preview deployments

Simple Docker file:

services:
   apache:
      image: xyz
   mysql:
      image: xyz

When a preview build is issued the container name will be something like apache-p0g0ck8c44o4oo4w808so8w4-pr615 while the primary build will be apache-p0g0ck8c44o4oo4w808so8w4-2132333212

When you terminal the primary build you can ping apache from mysql and mysql from apache but when you terminal into a preview build there are name resolution errors between containers when you use the service names UNLESS you use the container_name set by coolify. Thus you are unable to use service names directly in preview builds for network resolution

Build logs for preview builds show there is confusion from docker when creating the services as it sees the primary services as orphans because the project-namep0g0ck8c44o4oo4w808so8w4 is the same as the project name on the master build which means they are sharing networks and thus that's why there are name resolution issues.

2024-Dec-31 22:51:01.726049
docker exec j0cg004woswgw8k88g0k48ok bash -c 'SOURCE_COMMIT=f346f96b0c1939750307ca719be252af533fdd11 COOLIFY_BRANCH=master  docker compose --env-file /artifacts/j0cg004woswgw8k88g0k48ok/.env-pr-615 --project-name p0g0ck8c44o4oo4w808so8w4 --project-directory /artifacts/j0cg004woswgw8k88g0k48ok -f /artifacts/j0cg004woswgw8k88g0k48ok/coolify-compose.yml up -d'
2024-Dec-31 22:51:01.726049
time="2024-12-31T22:51:01Z" level=warning msg="Found orphan containers ([apache-p0g0ck8c44o4oo4w808so8w4-2132333212 mysql-p0g0ck8c44o4oo4w808so8w4-2132333212]) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up."
2024-Dec-31 22:51:01.726049
 Container apache-p0g0ck8c44o4oo4w808so8w4-pr-615  Running
2024-Dec-31 22:51:01.726049
 Container mysql-p0g0ck8c44o4oo4w808so8w4-pr-615  Running

Steps to Reproduce

See above

Example Repository URL

No response

Coolify Version

v4.0.0-beta.380

Are you using Coolify Cloud?

Yes (Coolify Cloud)

Operating System and Version (self-hosted)

Ubuntu 24.04.1 LTS

Additional Information

I believe the issue in general is that all preview builds and the "master" build share the same project-name from docker-compose. Simply changing this to be unique should fix the issue.

The project-name for a preview build should be something like p0g0ck8c44o4oo4w808so8w4-pr615 so as to not conflict.

Theres a few places this needs to be addressed:

Again what you'll notice here is that $this->application->uuid is used for both primary deployment and any preview deployments and thus causes all sorts of networking issues.

I think project-name should be using $this->container_name, of course this will probably cause orphans on upgrade (not that its hard to clean that up)

$this->container_name = generateApplicationContainerName($this->application, $this->pull_request_id);
if ($this->application->settings->custom_internal_name && ! $this->application->settings->is_consistent_container_name_enabled) {
if ($this->pull_request_id === 0) {
$this->container_name = $this->application->settings->custom_internal_name;
} else {
$this->container_name = "{$this->application->settings->custom_internal_name}-pr-{$this->pull_request_id}";
}
}

Or project-name itself could be declared as a property which is dynamic based on the above lines of code (and probably set in the same area)

Im willing to issue a PR on this if it's understood.

@tm1000 tm1000 added 🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization. labels Dec 31, 2024
@tm1000
Copy link
Author

tm1000 commented Jan 1, 2025

After more investigation I've determined the bug is not where I thought it was.

I went through and turned off the primary app and restarted the server.

Then I manually built a preview deployment from a PR and everything built but the containers are not able to talk to each other on their base container names. EG apache cant talk to mysql but it CAN talk to mysql-p0g0ck8c44o4oo4w808so8w4-pr-615

This works correctly if I start the primary app back up (non preview)

@tm1000
Copy link
Author

tm1000 commented Jan 1, 2025

This is a duplicate of #3511

@tm1000 tm1000 closed this as completed Jan 1, 2025
@github-actions github-actions bot removed 🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization. labels Jan 1, 2025
@tm1000 tm1000 closed this as completed Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant