docker
docker copied to clipboard
Enable exposed port to be configurable to run container in host networking mode on a port different than 80
If I'm running the container with --net=host, it can only be reached on port 80 (ports mapping is disabled when network mode is host).
It would be great to have the possibility to set the port where nginx will listen to with an environment variable (an example is this image: https://github.com/mesoscloud/chronos).
I looked a bit into this and found this mentioned in the official ngix docker repo
Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But envsubst may be used as a workaround if you need to generate your nginx configuration dynamically before nginx starts. https://github.com/docker-library/docs/tree/master/nginx#using-environment-variables-in-nginx-configuration
As of now I don't think envsubst is included by default with alpine. We need to include this when building the image:
RUN apk add --update $RUNTIME_DEPS && apk add --virtual build_deps $BUILD_DEPS && cp /usr/bin/envsubst /usr/local/bin/envsubst && apk del build_deps
Afterwards we can perform the environment substitution in the run.sh script.
This feature would be extremely helpful.
Port 80 is the default on many images. In the context of a Kubernetes pod, each container must have a unique port – so I cannot run Nginx and PHPMyAdmin within the same pod.
Solution: you can change the port with a Dockerfile.
FROM phpmyadmin/phpmyadmin
RUN sed -i 's/80/8080/g' /etc/nginx.conf
@KristianWindsor: Thanks for the info, It's not really a persistent solution because you have to do that after every container update.
But we do not have a nginx version anymore, right?
So it's easier to add this functionality using environment variables?
https://github.com/phpmyadmin/docker/blob/master/apache/Dockerfile
I have to look if it is possible with the image php gives us
A way to avoid building your own image (to keep things simpler) is to start the image like this:
docker run \
-it \
--rm \
--net=host \
--entrypoint=/bin/bash \
phpmyadmin/phpmyadmin:5.0.1 \
-c "sed -i 's/Listen 80/Listen 8080/g' /etc/apache2/ports.conf && /docker-entrypoint.sh apache2-foreground"
Thank you for the command I can integrate changing the port to an ENV variable now
Ref https://github.com/docker-library/php/issues/94#issuecomment-320695125
@J0WI would such a solution be accepted in the entrypoint using an ENV variable ?
Is there a use case to run them in the same pod? For Docker you can also use -p 8080:80
to expose it on a different port.
in Google Cloud Run, there is an already defined env variable PORT
(default to 8080), and it is supposed your container honor that variable.
Any updates about this feature?
Any updates about this feature?
Hi @J0WI You have more expertise than me, would you too consider this feature as valid ?
IMHO this shouldn't be changed in every image based on the PHP base image https://github.com/nextcloud/docker/pull/1504#issuecomment-862410960
Duplicate of #340
Done in #369