You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOMAD_PORT_<label> for a docker task in 0.9.0 series is set to the host static or dynamic port allocation. Previously, it was set to the port the service should bind to inside container.
Implementation Details
The fix requires some thought. port_map is a driver specific config currently. Task Runner and TaskEnv are not equipped to set the values properly.
Nomad v0.9 dropped the Prestart method for task drivers and inadvertently stopped properly setting this env vars in the process.
Fix
I think we can set these env vars directly in the Docker driver.
The only code that needs access to the PortMap occurs within Driver.StartTask and after (eg service registration in a postrun hook), so we should have have drivers populate their environment from their port map inside StartTask.
Update: To clarify any driver with a port_map is affected. Updated labels.
I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Nomad version
Tested with the following versions
Operating system and Environment details
macOS, but applies to Linux
Issue
NOMAD_PORT_<label>
for a docker task in 0.9.0 series is set to the host static or dynamic port allocation. Previously, it was set to the port the service should bind to inside container.Implementation Details
The fix requires some thought.
port_map
is a driver specific config currently. Task Runner and TaskEnv are not equipped to set the values properly.At entry of
taskDriver.StartTask(...)
invocation yet,port_map
isn't properly interpreted yet, andTaskEnv
hasnil
driverNet
in https://github.com/hashicorp/nomad/blob/v0.9.4/client/taskenv/env.go#L724-L730 . This means thatTaskEnv
setsNOMAD_PORT_<label>
would set to the assigned host port.Interestingly,
StartTask(...)
returns the port mapping and nomad attempts to set task env variables in the invocation in https://github.com/hashicorp/nomad/blob/v0.9.4/client/allocrunner/taskrunner/task_runner.go#L772 . Sadly this is too late as task already started and this env-var isn't effective.We may need drivers to set these port environment variables (with some provider helper functions).
Reproduction steps
nomad agent -dev
nomad job run ./example.hcl
nomad alloc logs --job example
On 0.9.0, the
NOMAD_PORT_db
matchesNOMAD_HOST_PORT_db
:Nomad 0.8.7 provides the expected behavior:
Job file (if appropriate)
The text was updated successfully, but these errors were encountered: