Skip to content

Fix documentation about mapping container port to a random free host port#18904

Closed
mindtraveller wants to merge 2 commits intogithub:mainfrom
mindtraveller:patch-2
Closed

Fix documentation about mapping container port to a random free host port#18904
mindtraveller wants to merge 2 commits intogithub:mainfrom
mindtraveller:patch-2

Conversation

@mindtraveller
Copy link
Copy Markdown

@mindtraveller mindtraveller commented Jul 1, 2022

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:

  • I have reviewed my changes in staging (look for the "Automatically generated comment" and click the links in the "Preview" column to view your latest changes).
  • For content changes, I have completed the self-review checklist.

@welcome
Copy link
Copy Markdown

welcome Bot commented Jul 1, 2022

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.

@github-actions github-actions Bot added the triage Do not begin working on this issue until triaged by the team label Jul 1, 2022
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 1, 2022

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 that have been changed in this pull request. It's provided to make it easy to review your changes on the staging site. Please note that changes to the data directory will not show up in this table.


Content directory changes

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

Source Preview Production What Changed
actions/using-containerized-services/about-service-containers.md fpt
ghec
ghes@ 3.5 3.4 3.3 3.2
ghae
fpt
ghec
ghes@ 3.5 3.4 3.3 3.2
ghae

@cmwilson21
Copy link
Copy Markdown
Contributor

@mindtraveller Thanks so much for opening a PR! I'll get this triaged for review ⚡

@cmwilson21 cmwilson21 added content This issue or pull request belongs to the Docs Content team actions This issue or pull request should be reviewed by the docs actions team waiting for review Issue/PR is waiting for a writer's review and removed triage Do not begin working on this issue until triaged by the team labels Jul 5, 2022
@martin389 martin389 added the needs SME This proposal needs review from a subject matter expert label Jul 12, 2022
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for opening a pull request! We've triaged this issue for technical review by a subject matter expert 👀

@github-actions
Copy link
Copy Markdown
Contributor

This is a gentle bump for the docs team that this PR is waiting for technical review.

@github-actions github-actions Bot added the SME stale The request for an SME has staled label Jul 19, 2022
@cmwilson21 cmwilson21 removed the SME stale The request for an SME has staled label Jul 20, 2022
@github-actions
Copy link
Copy Markdown
Contributor

This is a gentle bump for the docs team that this PR is waiting for technical review.

@github-actions github-actions Bot added the SME stale The request for an SME has staled label Jul 27, 2022
@cmwilson21 cmwilson21 removed the SME stale The request for an SME has staled label Jul 28, 2022
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 4, 2022

This is a gentle bump for the docs team that this PR is waiting for technical review.

@github-actions github-actions Bot added the SME stale The request for an SME has staled label Aug 4, 2022
@cmwilson21 cmwilson21 removed the SME stale The request for an SME has staled label Aug 5, 2022
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)."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 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 🙂

@lucascosti lucascosti added the invalid This issue/PR is invalid label Aug 22, 2022
@github-actions github-actions Bot closed this Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

actions This issue or pull request should be reviewed by the docs actions team content This issue or pull request belongs to the Docs Content team invalid This issue/PR is invalid needs SME This proposal needs review from a subject matter expert waiting for review Issue/PR is waiting for a writer's review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants