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

Enable exposed port to be configurable to run container in host networking mode on a port different than 80 #138

Closed
kanishkdudeja opened this issue Oct 20, 2017 · 17 comments

Comments

@kanishkdudeja
Copy link

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).

@sa3dany
Copy link

sa3dany commented Oct 24, 2017

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.

@KristianWindsor
Copy link

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.

@KristianWindsor
Copy link

KristianWindsor commented May 30, 2019

Solution: you can change the port with a Dockerfile.

FROM phpmyadmin/phpmyadmin
RUN sed -i 's/80/8080/g' /etc/nginx.conf

@ecdlguy
Copy link

ecdlguy commented Feb 17, 2020

@KristianWindsor: Thanks for the info, It's not really a persistent solution because you have to do that after every container update.

@williamdes
Copy link
Member

But we do not have a nginx version anymore, right?

@ecdlguy
Copy link

ecdlguy commented Feb 17, 2020

So it's easier to add this functionality using environment variables?

@williamdes
Copy link
Member

https://github.com/phpmyadmin/docker/blob/master/apache/Dockerfile

I have to look if it is possible with the image php gives us

@spantaleev
Copy link

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"

@williamdes
Copy link
Member

Thank you for the command
I can integrate changing the port to an ENV variable now

@williamdes
Copy link
Member

Ref docker-library/php#94 (comment)

@J0WI would such a solution be accepted in the entrypoint using an ENV variable ?

@J0WI
Copy link
Contributor

J0WI commented Mar 17, 2020

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.

@sergiokessler
Copy link

in Google Cloud Run, there is an already defined env variable PORT (default to 8080), and it is supposed your container honor that variable.

@simann
Copy link

simann commented Jun 3, 2021

Any updates about this feature?

@williamdes
Copy link
Member

Any updates about this feature?

Hi @J0WI
You have more expertise than me, would you too consider this feature as valid ?

@J0WI
Copy link
Contributor

J0WI commented Jun 16, 2021

IMHO this shouldn't be changed in every image based on the PHP base image nextcloud/docker#1504 (comment)

@williamdes
Copy link
Member

Duplicate of #340

@williamdes williamdes marked this as a duplicate of #340 Aug 3, 2023
@williamdes
Copy link
Member

Done in #369

@williamdes williamdes self-assigned this Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants