azukaar / Cosmos-Server

☁️ The Most Secure and Easy Selfhosted Home Server. Take control of your data and privacy without sacrificing security and stability (Authentication, anti-DDOS, anti-bot)
https://cosmos-cloud.io
Other
3.66k stars 130 forks source link

[BUG]: Container name in network mode replaced by digest #254

Closed srosorcxisto closed 6 months ago

srosorcxisto commented 6 months ago

What happened?

When restarting a system, any ServApp that uses the container network mode fails to start until the compose file is edited. This is due to Cosmos rewriting the compose file and squashing the network name and replacing it with an ephemeral idand adding an unsupported hostmame.

What should have happened?

The container should restart using the same network configuration that was originally set.

How to reproduce the bug?

  1. Start a container that references another contain for its network mode (such as "container:gluetun")
  2. observe that cosmos rewrote the network line to use the id instead of the container name and cosmos has added an illegal host name.
  3. Reboot the system
  4. The container fails to start because it can't find the container id

Relevant log output

Relevant log entry when attempting to start a container after system restart:

[ERROR] Docker - Cannot get container IP : Error response from daemon: No such container: 4aaf43c592ec0ba469de5f569b39d3db4001786a736b92711f5a705eab57ebae

Other details

I was not sure if this should be reported as a feature request or bug. Since it ultimately does result in breakage, I chose to initially submit as a bug. When loading an external docker compose file, cosmos replaces the container name with the id of a container when setting the network type.

As an example, if I have a container I want to route through gluetun, I would add this to the docker config:

network_mode: "container:gluetun"

This works as expected, however cosmos rewrites the docker-compose file to point to the container using the id like this:

"network_mode": "container:4aaf43c592ec0ba469de5f569b39d3db4001786a736b92711f5a705eab57ebae"

This is great, except that when the system is restarted for any reason, the container id is changed and any container that was pointing to the gluetun container will fail to boot until the dock-compose file is changed back to network_mode:

"container:gluetun".

Similarly, cosmos automatically adds a hostname to the compose file which has to be removed every time the container is pulled since hostnames are not compatible with container network modes. I have not found a workaround for this:

  "hostname": "4aaf43c592ec",

System details

azukaar commented 6 months ago

This is actually Docker not with Cosmos doing that, unfortunately you will have the same issues with any system (like Portainer) There is however a "solution" (or a hack) in COsmos to prevent this: set the label cosmos-force-network-mode to container:gluetun and it should revert Docker's change everytime it screws up your Container

srosorcxisto commented 5 months ago

Thanks! That worked like a charm!

Is there a place to contribute a pull request to the documentation? I did not see it as part of the repository. I am happy to take a crack at expanding the Networking documentation to include this if you would like. It is a very handy feature, and I am sure that it probably comes up a lot, especially for gluetun users since that is not part of the ServApps repository.

For that matter, is there a specific reason Gluetun is not in the repository, or just that no one has submitted a pull request before? I am happy to submit a pull request for that as well if its the latter.

azukaar commented 5 months ago

I'd love to get some help expanding the notification. Back then I started opening a repo and all that but I did not finish making it actually publish the doc on change. If you ping me on Discord I will keep your contact aside and will let you know once you can start contributing Thanks for the help 🙏