Dokploy / Dokploy/dokploy

Expose extra_hosts / ContainerSpec.Hosts in Swarm Settings UI

Open
#4,270 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
37.4k
Forks
3k
Avg merge
1d 3h
Merged PRs (30d)
73

Description

Summary

Dokploy's Swarm Settings dialog (Advanced → Cluster Settings → Swarm Settings) covers most ContainerSpec fields (Health Check, Restart Policy, Placement, Update Config, Rollback Config, Mode, Network, Labels, Stop Grace Period, Endpoint Spec) but is missing ContainerSpec.Hosts — the Swarm equivalent of Docker's --add-host / Compose's extra_hosts.

Tested on Dokploy v0.28.6.

Use case

Any app that needs to make SSR / server-side requests to a hostname that resolves publicly to the same host it runs on (hairpin-NAT situations). Concrete example: a Next.js app doing fetch('https://pre-prod.example.com/api/...') from inside the container, where pre-prod.example.com resolves to the droplet's public IP — Docker's default bridge usually cannot NAT the packet back to the host's own traefik, so the fetch times out.

The standard fix is to add a hosts entry inside the container pointing the public hostname to traefik's IP on the overlay network (extra_hosts: ["pre-prod.example.com:10.0.1.2"]). This works perfectly when applied manually via docker service update --host-add, but is wiped on every Dokploy Deploy / Rebuild because the UI recreates the service spec without it.

Other scenarios where this is needed:

  • Pointing a service at an internal API that isn't in public DNS
  • Overriding a hostname for staging (so the same code/env vars work in both environments)
  • Working around DNS issues on specific providers

Expected

New section inside Swarm Settings → Hosts (or a top-level "Extra Hosts" field under Advanced) accepting a list of entries like:

hostname: ip

These should populate ServiceSpec.TaskTemplate.ContainerSpec.Hosts (array of "IP HOSTNAME" strings) and survive redeploys.

Technical pointer

Docker Swarm API: https://docs.docker.com/reference/api/engine/version/v1.45/#tag/Service/operation/ServiceCreateTaskTemplate.ContainerSpec.Hosts. The Go SDK accepts this as swarm.ContainerSpec.Hosts []string.

Current workaround

Running a small systemd reconciler on the worker node that watches docker events --filter type=service --filter service=<name> and reapplies --host-add whenever the spec is regenerated. Works but obviously shouldn't be necessary.

Happy to open a PR if there's interest — most of the wiring already exists for the other ContainerSpec fields in the Swarm Settings modal.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the Swarm Settings dialog and compare how existing ContainerSpec fields are wired through deployment. Trace ServiceSpec.TaskTemplate.ContainerSpec.Hosts and the Go SDK representation, then add the Hosts input using the expected host/IP format. Done means entries persist in the service spec and survive Dokploy deploys and rebuilds.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, typescript
Domain
devops
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.