rnwood / smtp4dev

smtp4dev - the fake smtp email server for development and testing
BSD 3-Clause "New" or "Revised" License
2.94k stars 334 forks source link

URL configuration with environment variable doesn't work reliably #1525

Open maconfr opened 6 days ago

maconfr commented 6 days ago

I'm using the container image to start the smtp4dev server. I don't want to use privileged ports, even within the container, so i changed the ports for alll services. I'm using environment Variables to configure the ports, which works well for the SMTP and IMAP port, but not for the HTTP port.

Most of the time, the server starts with the default HTTP port 80. Console Output:

[...] Overriding HTTP_PORTS '80' and HTTPS_PORTS ''. Binding to values defined by URLS instead 'http://*:80'. Now listening on: http://[::]:80

Sometimes it actually starts with the configured port 5000. Console Output:

[...] Overriding HTTP_PORTS '80' and HTTPS_PORTS ''. Binding to values defined by URLS instead 'http://*:5000'. Now listening on: http://[::]:5000

For some statistics i started and stopped the container 20 times with the following docker command:

docker run -it --rm \
  -p 5000:5000 \
  -p 2525:2525 \
  -e ServerOptions__Urls="http://*:5000" \
  -e ServerOptions__Port=2525 \
  -e ServerOptions__ImapPort=2143 \
  "rnwood/smtp4dev:3.6.0"

In total the HTTP Server started 12 times with port 80 and 8 times with port 5000.

This only happens when i use the ServerOptions__Urls environment variable. When i use the cli parameter --urls, it works as intended 100% of the time. For example with this command:

clear; docker run -it --rm \
  -p 5000:5000 \
  -p 2525:2525 \
  -e ServerOptions__Port=2525 \
  -e ServerOptions__ImapPort=2143 \
  "rnwood/smtp4dev:3.6.0" \
    --urls "http://*:5000"

[...]
Overriding HTTP_PORTS '80' and HTTPS_PORTS ''. Binding to values defined by URLS instead 'http://*:5000'.
Now listening on: http://[::]:5000
jainal09 commented 4 days ago

+1 can confirm this issue occurs in 3.6.1 even though env ServerOptions__Urls=http://*:5001 is added in my case, 5-6/ 10 times it starts on port 80