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

Use of EXPOSE causes unnecessary ports being opened when changing ports #22

Open
Nbelles opened this issue Mar 19, 2024 · 4 comments
Open

Comments

@Nbelles
Copy link

Nbelles commented Mar 19, 2024

Hello,

I'm having some issues with using the default ports that are exposed. Once these ports are exposed, there is no way to unexpose them or change them. It is much preferable for a project to choose an arbitrary port (like the standard 80 and 443) for inside the container that users can then map to any port they want outside the container (using the standard docker run -p 80:1234 or docker compose). By using the EXPOSE command in the docker file, even if you map another port through the docker command line or in a docker compose, you still get extra exposed ports which might collide with other containers running.

EXPOSE ${HTTP_PORT} ${HTTPS_PORT}

@openspeedtest
Copy link
Owner

To assist in troubleshooting, could you please describe the steps required to replicate this issue?

@Nbelles
Copy link
Author

Nbelles commented Mar 19, 2024

Using the following docker-compose.yml, you can see in the following docker ps output that even though I only selected to expose port 10000, ports 3000 and 8080 are still exposed.

docker-compose.yml

version: "3"

services:
  openspeedtest:
    image: openspeedtest/latest
    ports:
      - "0.0.0.0:10000:3001"

docker ps

PORTS                                      
3000/tcp, 8080/tcp, 0.0.0.0:10000->3001/tcp

@openspeedtest
Copy link
Owner

What's your proposed solution? If this isn't a breaking change, please consider submitting a pull request (PR). Alternatively, could we specify a different unused port to avoid potential problems? I'm curious to understand the issue this behavior might create. I haven't personally encountered any problems, and you're the first to report it. This has me stumped!

@Nbelles
Copy link
Author

Nbelles commented Mar 22, 2024

Simply removing the line mentioned in the original post should do the trick*.

*Although it may be more intuitive to set the HTTP_PORT default to 8080 so CHANGE_CONTAINER_PORTS isn't required unless HTTPS_PORT is needed.

All the instances I have found in your documentation already have specific port mappings called out in both the docker run ... and docker-compose.yml methods so it shouldn't break any compatibility if people followed your documentation. If the proposed line is removed, only port 8080 will be exposed (I believe because of the base image you chose that exposes port 8080). If people want to remap this to something else, they can map port 10000 (or any random port outside the container) to 8080 (overwriting the default internal port) using something like docker run -p 10000:8080 ... and then setting CHANGE_CONTAINER_PORTS=True in the environment variables and setting either HTTP_PORT or HTTPS_PORT to 8080 (depending on their preference for http/https and this is why I recommend changing the default port from 3000 to 8080). If they want http and https, they can map 10000 to 8080 and 10001 to 8081 using something like docker run -p 10000:8080 -p 10001:8081 ... and then setting CHANGE_CONTAINER_PORTS=True in the environment variables and setting HTTP_PORT to 8080 and HTTPS_PORT to 8081.

Feel free to try this and verify this behavior is as described.

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