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.55k stars 124 forks source link

[BUG]: Docker Compose import ignores hostname #289

Open plangin opened 3 months ago

plangin commented 3 months ago

What happened?

When I import a docker compose, the hostname is ignored.

It could look like this:

services:
  pihole:
    container_name: pihole
    environment:
      FTLCONF_LOCAL_IPV4: 192.168.178.10
      TZ: Europe/Berlin
    hostname: pihole

Instead the hostname pihole, Cosmos Server creates some hostname like 97eb67d37625

Excerpt of generated Cosmos Compose:

      "entrypoint": "/s6-init",
      "hostname": "97eb67d37625",
      "network_mode": "cosmos-pihole-default",

What should have happened?

Create a new container with the hostname pihole.

How to reproduce the bug?

  1. Go to 'ServApps'
  2. Click on 'Import Compose File'
  3. Import some Docker Compose file with hostname information.

Relevant log output

No response

Other details

No response

System details

azukaar commented 3 months ago

hostname is forced to be the name of the container because otherwise it makes a lot of things confusing - that is the intended behaviour

EDIT: sorry closed the issue too fast, could you send the compose you are using so I can try reproduce the issue?

plangin commented 3 months ago

send the compose you are using so I can try reproduce the issue?

Sure:

services:
  mosquitto:
    container_name: mosquitto
    image: eclipse-mosquitto:2
    hostname: mosquitto
    restart: unless-stopped
    ports:
      - "1883:1883"

When importing this Docker Compose snippet, the Cosmos Compose seems to recognize and apply the desired hostname correctly when clicking on Next:

{
  "services": {
    "mosquitto": {
      "container_name": "mosquitto",
      "image": "eclipse-mosquitto:2",
      "hostname": "mosquitto",
      "restart": "unless-stopped",
      "ports": [
        "1883:1883"
      ],
      "network_mode": "cosmos-mosquitto-default"
    }
  },
  "networks": {
    "cosmos-mosquitto-default": {}
  }
}

But on the end, the resulting hostname was d329d1f3a41a, not mosquitto.

Technical background:

I prefer to use self-explanatory and static hostnames, so I can connect effortless to them. In that example I use Home Assistant, Zigbee2MQTT and other MQTT clients with the host 'mosquitto'.

azukaar commented 3 months ago

Tried it and it works with no issues on my end, my guess is you have something else (Unraid? Portainer?) that meddles with your container, because when you re-create container in docker, it re-assigns the hostname to some random BS (Docker quirks)

That said, Cosmos is supposed to prevent Docker from doing this (yeah it's nice like that! But only if you recreate from Docker itself) but it's not working in this case because the container is not in bridge mode. So I will adjust the code

image

plangin commented 3 months ago

Tried it and it works with no issues on my end, my guess is you have something else (Unraid? Portainer?) that meddles with your container

Nope, just NixOS and Cosmos Server was the first container I deployed on Docker.

because when you re-create container in docker, it re-assigns the hostname to some random BS

Aaah, re-creation seems to lead to this issue. I was able to scramble the hostname by just re-creating the container directly within Cosmos

azukaar commented 3 months ago

Aaah, re-creation seems to lead to this issue. I was able to scramble the hostname by just re-creating the container directly within Cosmos

Yes that is fixed in the 0.16 branch now