Troubleshooting
Telegraf cannot reach an InfluxDB container by its name
Short answer
Docker container names resolve only inside the Docker network, so a Telegraf service running on the host cannot use the container name with the published number. Point the InfluxDB output at the published host port, localhost with 8087 for an 8087:8086 mapping. If that address returns EOF, name resolution is fixed and a separate published-endpoint fault remains; verify it with a direct query to the query endpoint before touching Telegraf.
On this page
- Why a container name fails from the host
- The two errors and the layer each proves
- Example: reading the 8087:8086 mapping into the two correct URLs
- Point the host-side Telegraf at the published port
- Test the published endpoint before blaming Telegraf
- Keep the container name only by moving Telegraf onto the network
- Decision for each case
- Questions asked
A Telegraf service running directly on the host cannot reach an InfluxDB container by its Docker name: container names resolve only inside the Docker network, never on the host. Point the InfluxDB output at the port Docker publishes on the host — with an 8087:8086 mapping in the compose file, the host-side URL is http://localhost:8087. If that URL answers with EOF instead of data, the name problem is already fixed and a second fault at the published endpoint remains; reproduce it with a direct query test before changing Telegraf again. The sections below separate the two faults, read the mapping into the two correct URLs, and end with the decision for each case.
Why a container name fails from the host #
Docker gives each network its own name resolution: a service name or a container hostname such as influxdb resolves for containers attached to that network and for nothing else. A process running directly on the host uses the host's own resolver, which has no entry for that name. That is why the log shows dial tcp: lookup influxdb: no such host — the request dies in name resolution, before a TCP connection is opened and before any InfluxDB code runs.
No spelling of the container name fixes this from the host. The name is not resolvable there, so the only host-side address that reaches the container is the published port: the host side of the ports entry in the compose file.
The boundary cuts both ways. The mirror-image fault, a Telegraf container dialing a service on the host and hitting itself instead, is covered in Fix Telegraf MQTT connecting to localhost in Docker.
The two errors and the layer each proves #
The logs in this scenario show two different failures at two different layers, and they need different fixes. A lookup failure means no connection was ever attempted. EOF means the TCP connection to the published port was accepted, then closed before any HTTP response came back; the same fault seen from curl is curl: (52) Empty reply from server.
| URL tried from the host | Observed result | What the result proves |
|---|---|---|
| http://influxdb:8087 | dial tcp: lookup influxdb: no such host | Host-side name resolution fails; no connection is ever attempted |
| http://localhost:8087 | EOF on the write | TCP to the published port succeeds, then closes with no HTTP response: a published-endpoint fault, not a name fault |
| The container IP with the container-side port | Writes succeed | The InfluxDB service is healthy; this combination bypasses both the name and the published port |
The container-IP test succeeds because the host sits on Docker's bridge network and can route straight to a container address without the published port or any name lookup. That makes it a good diagnostic and a bad configuration: Docker reassigns container addresses whenever a container is recreated, so an address written into the config survives the first restart and breaks at the next redeploy.
Example: reading the 8087:8086 mapping into the two correct URLs #
A compose ports entry reads host side first, container side second. Worked through for the scenario above, where the host already runs one InfluxDB on 8086 and the container is published with an 8087:8086 mapping:
- host side: 8087 — the only number a host-side client dials
- container side: 8086 — the number the InfluxDB service listens on inside the container
Reading the mapping into URLs gives exactly two correct results:
- Telegraf on the host dials the host side: http://localhost:8087. The container name cannot appear in this URL.
- A client inside the same Docker network dials the name with the container side: http://influxdb:8086.
Cross-check: the working container-IP test connected on the container side, which confirms the service port is 8086. So a host-side URL ending in 8086 does not reach the container either — on this host it lands on the InfluxDB instance already installed there. One mapping, two URLs: localhost with the published number for host-side clients, the service name with the container-side number for clients on the network. Every other combination fails at one of the two layers above.
Point the host-side Telegraf at the published port #
Set the URL in the outputs.influxdb block of the Telegraf config to the host side of the mapping: http://localhost:8087. Database creation and writes then travel through the published endpoint, and the lookup error disappears.
Two details keep this correct. First, localhost from a host process means the host itself, which is what you want here; the same word inside a container means the container, which is the trap behind the mirrored case linked above. Second, the original attempt http://influxdb:8087 combined the wrong half of each side — a name the host cannot resolve with a number that exists only on the host — so no variation of it can work. Fix the URL once and stop iterating on the name.
Test the published endpoint before blaming Telegraf #
EOF means the TCP connection to the published port was accepted and then closed before any HTTP response came back. Telegraf has done its part: name resolution and connection both work. Reproduce the fault independently of Telegraf with a query against the same endpoint:
curl -G -u user:pass http://localhost:8087/query --data-urlencode "q=SHOW DATABASES"
Replace user:pass with a real read-only account. A database list here proves the endpoint is healthy and sends you back to read the exact Telegraf error; an empty reply, or curl: (52) Empty reply from server, confirms the fault sits at the published endpoint or the service behind it. Those checks cover it:
- Container-side number in the mapping. Docker's published side accepts the TCP connection itself and forwards inward, so a mapping whose container side points where nothing listens surfaces as a close, not as connection refused. Compare the compose entry against the port the service actually listens on.
- Mapping bound to one host address. A ports entry written against a specific host address serves that address only and leaves the loopback name closed; docker compose port, given the compose service name and the container-side number, prints the effective host mapping.
- Published versus exposed. An expose entry reaches containers on the network only and publishes nothing on the host, so a host-side dial has nothing to connect to; the ports entry with both sides is what creates the host endpoint.
- What holds the host-side number. Another process on the host may own that port and answer TCP without speaking the InfluxDB protocol; check the listener before editing the compose file.
- The container itself. If the direct container-IP test still writes successfully while the published port returns empty replies, InfluxDB is healthy and the work stays on the mapping.
Published ports are their own failure point on plant edge PCs: after a reboot the mapping can be up while the service behind it is not, which is covered in Why Docker published ports fail after an edge PC reboot. Once the direct query returns a database list, a remaining authorization failure is a credentials fault rather than a network fault — that case is handled in Fix Telegraf authorization not found on InfluxDB 2.
Keep the container name only by moving Telegraf onto the network #
If the URL has to keep the name — for config shared with a fully containerized deployment — run Telegraf itself as a container attached to the same compose network as InfluxDB. There the name resolves, and the correct URL pairs the name with the container-side number, not with the published host number. Host-side tools keep using the published endpoint; nothing about the mapping changes. The layout where Telegraf and InfluxDB both run as containers is walked through end to end in the guide to connecting Telegraf to InfluxDB 2.x in Docker.
Decision for each case #
Each observed result maps to one action:
- lookup influxdb: no such host from a host-side Telegraf: replace the URL with the published host side of the mapping. No host-side spelling of the container name exists.
- EOF from the published port: stop editing Telegraf and run the direct query test. The config is correct at this point; fix the endpoint it points at.
- Empty reply from the direct test too: verify the container-side number in the mapping, whether the mapping is bound to a single host address, whether the port was only exposed rather than published, what else holds the host-side port, and whether the container is running.
- Database list from the direct test, but Telegraf still fails: read the new Telegraf error literally — an authorization message is a credentials problem, and a renewed lookup error means the URL was reverted.
- Container name required: run Telegraf on the compose network and pair the name with the container-side number.
- Container IP works: use it once to prove the service is healthy, then remove it; an address in the config breaks at the next recreate.
Questions asked
Why does Telegraf report lookup influxdb: no such host?
Docker resolves service and container names only for containers attached to that Docker network, using its own internal resolution. A program running directly on the host asks the host's own resolver, which has no entry for the name influxdb, so the request fails before any TCP connection is opened. Repoint the InfluxDB output at the published host port; the name itself is unreachable from the host under any spelling.
Why does the container IP work when the container name does not?
The host sits on Docker's bridge network and can route directly to a container address without the published port or any name lookup, so the write succeeds and proves the InfluxDB service is healthy. Treat the direct address as a one-time diagnostic only.
Which address does a containerized Telegraf use for the same InfluxDB?
A Telegraf container attached to the same compose network resolves the service name, and the correct address pairs that name with the container-side number from the mapping. For an 8087:8086 mapping that means the service name on port 8086. The published host number belongs to host-side clients only; inside the network nothing listens on it.
Does an EOF error mean InfluxDB itself is down?
No. EOF says the connection to the published port was accepted and then closed without an HTTP response, so the published endpoint is the suspect: the container-side number in the mapping, a mapping bound to a single host address, another process holding the host-side port, or the container service itself. Run the direct query test against the endpoint from the host to separate those before changing Telegraf again.