Skip to content

Preserve service network aliases and healthcheck in generated Compose output#91

Draft
Copilot wants to merge 3 commits into
masterfrom
copilot/fix-issue-89-service-network-attachment
Draft

Preserve service network aliases and healthcheck in generated Compose output#91
Copilot wants to merge 3 commits into
masterfrom
copilot/fix-issue-89-service-network-attachment

Conversation

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown

docker-autocompose was collapsing service network attachments to name-only output, dropping per-network attributes like Aliases, and it was not serializing Config.Healthcheck. This change keeps service-level network details from docker inspect and maps healthcheck fields into Compose-compatible output while preserving existing default-network behavior.

  • Service network attachment fidelity

    • Read NetworkSettings.Networks as structured per-network config instead of a set of names.
    • Preserve Aliases per network.
    • Emit service networks: as:
      • mapping form when per-network config exists (e.g., aliases),
      • list form for simple network-only attachments.
  • Top-level network declarations

    • Keep existing top-level networks generation unchanged.
    • Ensure service-level services.<name>.networks and top-level networks coexist correctly.
  • Healthcheck serialization

    • Add mapping from inspect healthcheck to Compose:
      • Testtest
      • Intervalinterval
      • Timeouttimeout
      • Retriesretries
      • StartPeriodstart_period
    • Normalize integer duration values into Compose-friendly duration strings (<ns>ns).
  • Regression coverage

    • Add focused tests for:
      • alias preservation in service-level network config,
      • healthcheck preservation,
      • simple custom-network list-form behavior,
      • unchanged default-network (network_mode) behavior.
services:
  svc:
    networks:
      custom_net:
        aliases:
          - svc
          - db
    healthcheck:
      test: ["CMD-SHELL", "echo ok"]
      interval: "1000000000ns"
      timeout: "2000000000ns"
      retries: 3
      start_period: "3000000000ns"

networks:
  custom_net:
    external: true
    name: custom_net
Original prompt

Implement a fix for issue #89 in Red5d/docker-autocompose.

Context:

  • Repository: Red5d/docker-autocompose
  • Issue: https://github.com/Red5d/docker-autocompose/issues/89
  • Relevant comment: https://github.com/Red5d/docker-autocompose/issues/89#issuecomment-4645166865

Observed problem:

  • The tool currently drops service-level Docker network attachment details when reconstructing Compose output from docker inspect data.
  • In particular, NetworkSettings.Networks.<network>.Aliases is not preserved.
  • The tool also appears to omit Config.Healthcheck entirely.

Current implementation details:

  • In src/autocompose.py, service networks are currently collapsed into a set of network names, which loses nested per-network attributes like aliases.
  • Top-level network definitions are generated separately, but service-level networks: output cannot currently express mapping-form network configuration.
  • There is no serialization path for Config.Healthcheck into Compose healthcheck: output.

Required changes:

  1. Preserve service-level network attachment configuration from docker inspect.
    • Read cattrs["NetworkSettings"]["Networks"].
    • Preserve per-network aliases at minimum.
    • Emit service networks: in Compose-compatible form:
      • use mapping form when per-network options exist
      • otherwise keep valid minimal output for simple cases
  2. Keep top-level network definitions working.
    • Do not break the existing generation of top-level networks: entries.
    • Ensure service-level network config and top-level network declarations coexist correctly.
  3. Add healthcheck serialization.
    • Read cattrs["Config"]["Healthcheck"].
    • Map Docker inspect fields to Compose healthcheck keys:
      • Test -> test
      • Interval -> interval
      • Timeout -> timeout
      • Retries -> retries
      • StartPeriod -> start_period
    • Convert Docker duration values to Compose-friendly duration strings if needed.
  4. Add or update tests to cover the regression.
    • aliases are preserved in service network config
    • healthcheck is preserved
    • simple network-only cases still work
    • existing behavior for default networks remains intact where appropriate

Implementation guidance:

  • Favor preserving aliases exactly as returned by inspect for the initial fix rather than filtering them aggressively.
  • Keep the patch focused on issue lost aliases #89.
  • Update tests and any fixtures as needed.

Deliverable:

  • Open a pull request against master implementing the above fixes with a concise PR title and description.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Try and figure out what the actual issue is here and what should be done to fix it.

Assistant: The actual issue is not just “aliases are lost” — it’s that docker-autocompose currently reconstructs only a very shallow subset of network and container config, so it drops per-network service details like aliases, and it also omits healthcheck. The code is reading the raw Docker inspect data, but it never maps those fields into Compose output.

Specifically:

  • For networks, the tool currently stores only the set of network names for the service, not the per-network config object. In src/autocompose.py, values["networks"] is built as a set of network names from NetworkSettings.Networks.keys(). That means fields under each network like Aliases, IPv4Address, etc. are discarded immediately. Later it only emits top-level network definitions like external and name, not service-level network attachments. So aliases cannot survive with the current data model.
  • For health checks, there appears to be no code path at all that reads Config.Healthcheck and converts it into Compose healthcheck: output.
  • The user’s example confirms this: Docker inspect shows aliases under NetworkSettings.Networks.<network>.Aliases, and healthcheck under Config.Healthcheck, but the generator never serializes either of those into the compose structure.

The key code causing the network-loss problem is here:

"networks": {
    x for x in cattrs.get("NetworkSettings", {}).get("Networks", {}).keys() if x not in default_networks
},
...
else:
    networklist = c.networks.list()
    for network in networklist:
        if network.attrs["Name"] in values["networks"]:
            networks[network.attrs["Name"]] = {
                "external": (not network.attrs["Internal"]),
                "name": network.attrs["Name"],
            }

What the bug really is

docker-autocompose is treating:

  • top-level Compose networks
  • and service-level network attachments

as if they were the same thing.

But in Compose they are different:

  • top-level networks: defines the network objects
  • service-leve...

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Fix issue #89 to preserve network attachments and healthcheck Preserve service network aliases and healthcheck in generated Compose output Jun 8, 2026
Copilot AI requested a review from Red5d June 8, 2026 03:57
Copilot finished work on behalf of Red5d June 8, 2026 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants