Hostname support for backup container
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 180
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
Hi 👋 ,
currently, stack-back identifies its own container by checking if the container ID starts with the hostname:
if container_data.get("Id").startswith(socket.gethostname()):
self.this_container = Container(container_data)
This works fine when using Docker's default behavior (hostname = container ID prefix), but fails when a custom hostname is set , for example in docker-compose.yml:
services:
backup:
hostname: "${COMPOSE_PROJECT_NAME}-backup"
This results in the error:
ValueError: Cannot find metadata for backup container
Use Case
Setting a custom hostname like ${COMPOSE_PROJECT_NAME}-backup is useful for:
- Consistent identification across container restarts
- Better monitoring and metrics (e.g., in Prometheus/Grafana)
- More readable hostnames in logs and dashboards
Proposed Solution
Extend the container detection logic to support both the original ID-based method and hostname-based detection:
for container_data in all_containers:
container_id = container_data.get("Id", "")
container_hostname = container_data.get("Config", {}).get("Hostname", "")
if container_id.startswith(socket.gethostname()) or container_hostname == socket.gethostname():
self.this_container = Container(container_data)
break
Benefits
- Maintains backward compatibility with existing setups
- Allows users to set custom hostnames for better monitoring
- No breaking changes to current functionality
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/restic_compose_backup/containers.py around line 410, where the backup container is identified from Docker metadata. Reproduce the failure with the custom hostname shown in the issue, then verify that both the default ID-based setup and the hostname-based setup locate the backup container without the metadata error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, docker-compose, python
- Domain
- infrastructure
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100