Skip to content

tasks.py: _container_exposed_port() calls docker.from_env but 'import docker' was dropped in e2c6309 #627

Description

@Valyrian-Code

Summary

Commit e2c6309 ("Improvments to Docker Compose and cleanup of env variables") removed the top-level import docker from src/tasks.py and reworked _docker_host_ip() to use a plain socket instead of the Docker SDK. However, _container_exposed_port() still calls the SDK:

client = docker.from_env(version="1.24")

With no import docker in the module, that line raises:

NameError: name 'docker' is not defined

How to reproduce / effect

_container_exposed_port() is reached from _geonode_public_port()update() on container start whenever GEONODE_LB_PORT is unset. The NameError is swallowed by the function's own try/except, which prints a traceback and falls back to the hardcoded "80". So on affected startups:

  • the Docker-API port detection never works (always returns 80), and
  • a traceback is printed in the entrypoint logs every time.

A quick confirmation that the name is undefined in the current module:

import ast
tree = ast.parse(open("src/tasks.py").read())
# no Import/ImportFrom node binds the name "docker", yet "docker.from_env(" is present

Possible fixes

  1. Minimal — re-add import docker (restores the previous behavior).
  2. Consistent with the cleanup — drop the Docker-SDK branch in _container_exposed_port() the way _docker_host_ip() was already moved off the SDK, and detect the port another way (or rely on GEONODE_LB_PORT).

Happy to open a PR for whichever direction you prefer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions