-
-
Notifications
You must be signed in to change notification settings - Fork 870
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
network conflict #1004
Comments
Hi, yes you are right, this is a bug that I am seeing for some time you can not deploy 2 equal templates because it is possible to mix the information and cause bad gateway errors or something like that and it is because in the dokploy-network the service names must be unique, currently I have not found a way to solve it that is elegant, I know it is something related to networks but I have no idea to solve it, I have tried different methods but none with the success I want without having to do a lot of magic behind compose. If you have any idea how to solve it in an elegant and direct way that is not something so manual would be great I believe is related to this #821 |
maybe, You can add a random variable which can into docker-compose? |
how about insert service-name into configuration. |
I think this can solve the problem of official templates at least. |
Yes, I was thinking about some of that, I just didn't like it because it was something that had to be done manually and I don't know how comfortable people would feel doing that. I assumed that adding --project-name would add the prefix to all containers, and it does but in the internal way of communication it directly uses the name of the service, so if you have a service like db in multiple compose, there might be problems. https://docs.docker.com/reference/cli/docker/compose/#options yes a temporary solution is to add a prefix to every container |
@Siumauricio is prefixing names a solution to #821 as well? |
Yes @TheOnlyWayUp , that really should be the only solution, add a prefix to each container, to prevent containers from colliding with names. |
Randomize Compose works but each time you create a service specially from the templates we need to randomize and update a domain, which is a manual work again. but i was thinking if there is a way to reuse the Randomize Compose component for each deployment even that would work instead of rewriting the entire code for prefix |
@Siumauricio, I believe this solution from @theboringhumane fixes this issue as well - #821 (comment). |
@TheOnlyWayUp Can you add steps to fix the issue? Or if there's anything from dokploy codebase change should I make |
@Siumauricio the way that Coolify handles this is by assigning a
This means that common service hostnames like This will be the case for the majority of resources. Additionally, similar to what @QThans mentioned, Coolify implicitly adds the resource When "opt-in", these services are exposed on the global network with a suffixed hostname, i.e. For example, suppose we "opt in" to expose the superset compose resource, which contains the superset, db, and redis services, to the global Following Coolify's example, environment variables such as This is not perfect and not saying Dokploy needs to mimic it completely, although personally, I think it is a flexible design that was easy to use and understand. More docs here: |
Thanks @nktnet1 for the explanation and Yes, the truth is that I have thought about that solution, however it seems to me quite a lot of work to be naming for example an environment variable with the prefix of the UUID, which is probably the most optimal solution to prevent any kind of conflict, although I think that coolify internally after deploying the docker compose makes some kind of connection between networks manually. |
Do you mean a lot of work for users, or for this to be implemented in Dokploy? I think the majority of the time, the services that you would "opt-in" to be on the global In the less common scenario where you want to reference an API service (like We can infer from things like the docker-compose service name, protocol, port, and resource UUID, i.e. generating something like # Internal URL inputs:
# - protocol: http
# - service name: gotenberg
# - resource UUID: `abcefg`
# - port: 3000
# Internal URL output:
http://gotenberg-abcdefg:3000 to mimic the behaviour of a database's internal URL. |
So you mean that before creating the template, in runtime we add a prefix to all services, and expose an environment variable that is I think adding documentation would make it easier, I will try to implement a solution for this, only we would have to change the templates. Example if we have this wordpress template: version: "3.8"
services:
wordpress:
image: wordpress:6.7.1
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress_data:/var/www/html
db:
image: mysql:5.7.34
networks:
- dokploy-network
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_ROOT_PASSWORD: rootpass
volumes:
- db_data:/var/lib/mysql
volumes:
wordpress_data:
db_data: So we might need to convert to like this version: "3.8"
services:
wordpress-${DOKPLOY_SERVICE_UUID}:
image: wordpress:6.7.1
environment:
WORDPRESS_DB_HOST: db-${DOKPLOY_SERVICE_UUID}
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress_data:/var/www/html
db-${DOKPLOY_SERVICE_UUID}:
image: mysql:5.7.34
networks:
- dokploy-network
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_ROOT_PASSWORD: rootpass
volumes:
- db_data:/var/lib/mysql
volumes:
wordpress_data:
db_data: Then in runtime, we will apply the changes so that the template automatically has the assigned values and becomes this version: "3.8"
services:
wordpress-abcdef:
image: wordpress:6.7.1
environment:
WORDPRESS_DB_HOST: db-abcdef
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress_data:/var/www/html
db-abcdef:
image: mysql:5.7.34
networks:
- dokploy-network
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_ROOT_PASSWORD: rootpass
volumes:
- db_data:/var/lib/mysql
volumes:
wordpress_data:
db_data: Correct me @nktnet1 If I'm wrong, what do you think? this will be apply only to templates |
Thanks for responding with a concrete example @Siumauricio. The way Coolify does it is a bit more implicit - the edtiable (source) template stays the same from a user's perspective. While the resource Users don't have to worry about the existence of the
coolify-preview-compose-demo.webmNow, only when users "opt-in" to be on the global network, that's when I guess the main point I'm getting at is, ideally, everything regarding naming should still work the same as it currently does in Dokploy without the existence of Hope this makes sense ^^. I think your suggested solution also has its benefit, with everything being explicitly viewable and editable by the user (less magic). I'm also happy with that solution, as it ultimately solves the problem at hand. |
I think the randomize feature is aligning with that behaviour, it would take little change to adapt the logic. Here is the PR, I tried it and it works, at the end I reused some methods of the randomizeCompose method, and in runtime I add the prefixes to the container_names and the nets. Implemented in #1276 and then we internally create the network and asociate the dokploy-traefik to the network btw activating this option doesn't add the dokploy-network to any of the service thanks @nktnet1 |
Thanks @Siumauricio for the speedy pull request 🚀🚀! I'll take a look at it, and will move future discussions to #1276. |
To Reproduce
using two same docker-compose to create services.
Current vs. Expected behavior
if deploy 2 compose has same configuration, the second deploy will using the first. for example, if there are all have pg, the second service will connect to the pg from the first service.
Provide environment information
Which area(s) are affected? (Select all that apply)
Docker Compose
Are you deploying the applications where Dokploy is installed or on a remote server?
Same server where Dokploy is installed
Additional context
No response
Will you send a PR to fix it?
Yes
The text was updated successfully, but these errors were encountered: