Skip to content

Set $PORT for containers #2258

@evankanderson

Description

@evankanderson

(Copied from an earlier discussion about 2 months ago which didn't make it into an issue somehow.)

Our runtime spec says that the $PORT environment variable WILL indicate which port the environment will attempt to connect the container on. Ideally, all our customers would read our documentation and consume $PORT without needing any external assistance (flags, config, etc).

Unfortunately, our users are in as much of a rush as we are, so we should try to choose our defaults so that the maximum number of cases just work. Based on our experience, we default the containerPort to 8080 if unset, to catch the common use case. In some other cases, the container may expose a flag which allows the user to choose which port to run the server on. The user can set this flag in their configuration to $PORT to get the same behavior as our ideal, with the cost of one extra command-line flag.

In other cases, the built container may expose some other port which is hard-coded; if we are able to parse the metadata, we could extract the port from the EXPOSE command. If all of these fail, the customer should be able to set container.ports[0].containerPort to the hard-coded port in their docker image.

Expected Behavior

The PORT environment variable is set based on our best determination for the containerPort:

  1. User's explicit yaml.
  2. Docker EXPOSE metadata from image.
  3. Default of 8080.

Actual Behavior

We always assume 8080.

See also #2101, which is a slightly different issue about our ability to consume the reasonable value for containerPort.

Metadata

Metadata

Assignees

Labels

area/APIAPI objects and controllersarea/networkingkind/bugCategorizes issue or PR as related to a bug.kind/cleanupCategorizes issue or PR as related to cleaning up code, process, or technical debt.kind/specDiscussion of how a feature should be exposed to customers.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions