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

Environment variable hostname not respected in docker (maybe linux in general) #160

Open
grasdk opened this issue Jan 10, 2025 · 5 comments

Comments

@grasdk
Copy link

grasdk commented Jan 10, 2025

With DefaultHostname=%HostName% in webone.conf, the docker container's internal IP addresss is used, rather than the container's hostname.

Started the docker container using argument --hostname mytest
A shell in the container shows that it is respected in the environment

# hostname
mytest

Also tested with a small program built inside the container, which printed the hostname mytest

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine($"Machine Name: {Environment.MachineName}");
    }
}

Webone is running, but the proxy is using the container's internal IP rather than the hostname provided. You can see this when looking in the network tab of your browser:
image

Also the default page shows similar problems:
image

The problem might be in lines 218-226 in ConfigFileLoader, probably in line 220, though I can't see how.

@grasdk
Copy link
Author

grasdk commented Jan 10, 2025

Why is this important?

Along with the port issue (#156), this is what would allow a docker container to be "plug and play". You might use the a webone.conf placed inside the container (not in a mounted volume) which just referred to %HostName%´ and %SERVICE_PORT%`, and you could start your container with these to environment variables set as part of the docker run command, like this:

docker run -d -p 8181:8181 --name webone \
-e SERVICE_PORT=8181 \
--hostname mytest
webone-mycontainer

Very simple and easy to use for most people. Only if you need specialized webone.conf you would need to bother with volume mounts etc...

@atauenis
Copy link
Owner

As a part of #156 I'm planning to add support for embedding any environment variables to the DefaultHostName. Probably there are no other possible ways to tell dockerized WebOne its external IP address.

WebOne is using a simple own IP/hostname detection algorithm:

  1. It is looking to Host and Referrer headers of HTTP request. This is used for internal pages.
  2. It is looking to incoming connection properties for local IP. This is ok for Linux, but not for gray IP with NAT (such as Docker). Running any servers via NAT is always a problematic thing.
  3. It is looking to all detected machine IPs, system host name, and [HostNames] list.
  4. It is looking to DefaultHostName as a last option if nothing of previous gives a result. It is ok for Windows, but not for other OSes.

The problem might be in lines 218-226 in ConfigFileLoader, probably in line 220, though I can't see how.

Yes, all right. And in lines 357-362, where [HostNames] list is processing. The problem is that these lines are directly adding to WebOne memory, without proper processing here. Program.ExpandMaskedVariables function should be useful here. It is processing both system environment variables and many WebOne internal variables.

@grasdk
Copy link
Author

grasdk commented Jan 11, 2025

As a part of #156 I'm planning to add support for embedding any environment variables to the DefaultHostName.

Cool, looking forward to it ;)

atauenis added a commit that referenced this issue Jan 12, 2025
@atauenis
Copy link
Owner

atauenis commented Jan 12, 2025

In latest commit in dev I have added support for using environment variables in most of webone.conf options. Including DefaultHostName too. So it's now possible to set real IP address via something like DefaultHostName=%SERVICE_IP% and setting $SERVICE_IP via Docker configuration. And similar way to specify a port will work too.

@grasdk
Copy link
Author

grasdk commented Jan 12, 2025

@atauenis Great. This is nice progress. I just tested it. Here are some findings:

I tested that both setting the $HOSTNAME variable and a custom variable $PROXY_HOSTNAME using docker run arguments and corresponding naming in webone.conf

docker run arguments naming in webone.conf
--hostname localhost DefaultHostName=%HOSTNAME%
-e PROXY_HOSTNAME=localhost DefaultHostName=%PROXY_HOSTNAME%

Both work on the info page. The css-stylesheet is loaded using the given name - I alto tried with other names than localhost which also worked.

However. When I load something more complex, e.g. vogons, there is some variable substitution missing. See screenshots below

OK info page
image

Error on vogons load: PROXY_HOSTNAME not sustituted
image

Error on vogons load: HOSTNAME not sustituted
image

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

2 participants