mendhak / docker-http-https-echo

Docker image that echoes request data as JSON; listens on HTTP/S, useful for debugging.
https://code.mendhak.com/docker-http-https-echo/
MIT License
624 stars 136 forks source link

Allow environment variable to specify port #3

Closed AceHack closed 4 years ago

AceHack commented 4 years ago

80 does not work in a container if you are not root. Thanks.

AceHack commented 4 years ago

It would be great if the name of that env was PORT

mendhak commented 4 years ago

Can you explain a bit, I'm not understanding the problem.

To use a different port just use -p to map from another port to 80 inside.

docker run -p 8080:80 -p 8443:443 --rm -t mendhak/http-https-echo
AceHack commented 4 years ago

I want to change the port inside the container not outside. 80 requires running as root and we use this container for troubleshooting in our EKS cluster where we are not allowed to run as root. Also, we use this knative service so it would be nice if the PORT env variable inside the container was able to control what port it listens on. If it's not there 8080 should be the default as it does not require running as root. If you would like to reproduce the problem run:

docker run -p 8080:80 -p 8443:443 --rm --user 1000 -t mendhak/http-https-echo

You can see the project you forked from now does this, the default should just be 8080 though not 80. https://github.com/solsson/docker-http-echo/blob/fdde39e26163dca48017ca70d6c9282e5cee27fd/index.js#L50

Thanks.

AceHack commented 4 years ago

He also handles sigint too https://github.com/solsson/docker-http-echo/blob/fdde39e26163dca48017ca70d6c9282e5cee27fd/index.js#L53-L67

mendhak commented 4 years ago

Aha now I see what you mean after that explanation.

I have added environment variables HTTP_PORT and HTTPS_PORT - since there are two ports being listened on. I've added this and examples to the README.md also.

I have defaulted to 80/443 so as to not break existing runners expecting 80/443.

Now you can try your command but add the environment variables:

docker run -e HTTP_PORT=8888 -e HTTPS_PORT=9999 -p 8080:8888 -p 8443:9999 --rm --user 1000 -t mendhak/http-https-echo

I've pushed to docker hub

mendhak commented 4 years ago

The SIGINT has been handled yesterday as well, both the SIGINT handling and environment should now be in docker hub, you'll need to pull latest

AceHack commented 4 years ago

Thank you

mendhak commented 4 years ago

Thanks for raising it @AceHack