Fix documentation about mapping container port to a random free host port#18904
Fix documentation about mapping container port to a random free host port#18904mindtraveller wants to merge 2 commits intogithub:mainfrom mindtraveller:patch-2
Conversation
|
Thanks for opening this pull request! A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the contributing guidelines. |
Automatically generated comment ℹ️This comment is automatically generated and will be overwritten every time changes are committed to this branch. The table contains an overview of files in the Content directory changesYou may find it useful to copy this table into the pull request summary. There you can edit it to share links to important articles or changes and to give a high-level overview of how the changes in your pull request support the overall goals of the pull request.
|
|
@mindtraveller Thanks so much for opening a PR! I'll get this triaged for review ⚡ |
|
Thanks for opening a pull request! We've triaged this issue for technical review by a subject matter expert 👀 |
|
This is a gentle bump for the docs team that this PR is waiting for technical review. |
|
This is a gentle bump for the docs team that this PR is waiting for technical review. |
|
This is a gentle bump for the docs team that this PR is waiting for technical review. |
| When you map ports using the `ports` keyword, {% data variables.product.prodname_dotcom %} uses the `--publish` command to publish the container’s ports to the Docker host. For more information, see "[Docker container networking](https://docs.docker.com/config/containers/container-networking/)" in the Docker documentation. | ||
|
|
||
| When you specify the Docker host port but not the container port, the container port is randomly assigned to a free port. {% data variables.product.prodname_dotcom %} sets the assigned container port in the service container context. For example, for a `redis` service container, if you configured the Docker host port 5432, you can access the corresponding container port using the `job.services.redis.ports[5432]` context. For more information, see "[Contexts](/actions/learn-github-actions/contexts#job-context)." | ||
| When you specify the Docker container port but not the host port, the host port is randomly assigned to a free port. {% data variables.product.prodname_dotcom %} sets the assigned host port in the service container context. For example, for a `redis` service container, if you configured the Docker container port 5432, you can access the corresponding host port using the `job.services.redis.ports[5432]` context. For more information, see "[Contexts](/actions/learn-github-actions/contexts#job-context)." |
There was a problem hiding this comment.
👋 Thanks for this PR, @mindtraveller, but IIUC, these changes aren't correct. Only specifying one value for port will set the Docker host port to that value, and when the container is created, the port in the container will be randomly generated. If the host port was randomly generated, then other processes on the runner wouldn't know the port to be able to access the container's service.
There was a problem hiding this comment.
Hey!
Even though I cannot find the exact description in the Docker docs, there are some examples in google regarding that topic:
https://stackoverflow.com/questions/60109556/expose-random-port-to-docker-compose-yml
https://stackoverflow.com/questions/49074157/how-do-i-find-out-which-random-port-docker-has-chosen
These answers make it clear that the host port is randomly selected, and in configuration container port is provided. That makes total sense, because it might be that you don't know/don't control what port is free in the host system you start a docker container in.
There was a problem hiding this comment.
🤔 I admit that I'm now getting confused 😅, but I'm certainly no Docker expert. I'll try and get one of our Actions engineers to confirm 🙂
Why:
I found a mistake in the docs about port mapping in the services section of the Actions documentation. This PR corrects it.
What's being changed (if available, include any code snippets, screenshots, or gifs):
The documentation page is changed.
Check off the following: