Fix Portainer Agent Connect β Agent Not Reachable
DodaTech
Updated 2026-06-24
2 min read
In this tutorial, you'll learn about Fix Portainer Agent Connect. We cover key concepts, practical examples, and best practices.
You deploy the Portainer Agent container on a remote Docker host, add it in Portainer, and the environment shows a red "Unreachable" badge. You can ping the host from the Portainer server, but the agent won't connect.
Wrong β
# Agent deployment on remote host
docker run -d \
--name portainer_agent \
--restart always \
-p 9001:9001 \
-v /var/run/docker.sock:/var/run/docker.sock \
portainer/agent:latest
In Portainer, you add the environment:
```text
Environment type: Agent
URL: 192.168.1.100:9001
Status: `Unreachable`
You verify the agent is running:
```bash
docker ps | grep portainer_agent
# portainer_agent is up
But `curl 192.168.1.100:9001` from the Portainer server times out.
## Right β
**Check agent networking:**
The agent must be reachable from the Portainer server. Use `--net=host` or correct port mapping:
```bash
docker run -d \
--name portainer_agent \
--restart always \
--network host \ β recommended for agent
-v /var/run/docker.sock:/var/run/docker.sock \
portainer/agent:latest
**Or with explicit port mapping and firewall:**
```bash
docker run -d \
--name portainer_agent \
--restart always \
-p 9001:9001 \
-v /var/run/docker.sock:/var/run/docker.sock \
portainer/agent:latest
**Open firewall:**
```bash
sudo ufw allow 9001/tcp
# Or with iptables:
sudo iptables -A INPUT -p tcp --dport 9001 -j ACCEPT
**Verify connectivity:**
```bash
# From the Portainer server
curl http://192.168.1.100:9001/ping
# β 200 OK
Then in Portainer, reβadd the environment:
β
Environment connected
Docker Host: 192.168.1.100
Version: 24.0.7
Containers: 8
## Root Cause
Portainer Agent uses a lightweight HTTP API on port 9001. If a firewall blocks the port, or Docker's bridge network doesn't route correctly to the host interface, the Portainer server can't reach the agent.
## Prevention
- Use `--network host` for agents β simplifies networking and avoids port mapping issues.
- Ensure port 9001 is open on the remote host's firewall before deploying the agent.
- Use Portainer's **Agent Setup** script from the UI β it generates the correct `docker run` command with TLS settings.
- For multiβhost setups, consider a Docker Swarm or Kubernetes environment instead of individual agents.
## Common Mistakes with agent connect
1. **Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors**
2. **Non-exhaustive pattern matches that compile with warnings then crash at runtime**
3. **Misunderstanding that `String` is `[Char]` with poor performance for large text operations**
These mistakes appear frequently in real-world PORTAINER code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
## Practice Exercise
**Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.**
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
## FAQ
<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Does the agent need TLS?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: TLS is optional but recommended for production. Portainer can generate the certificates or you can provide your own.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Can I run the agent on <a href="/operating-systems/windows/">Windows</a>?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Yes β Portainer Agent supports <a href="/operating-systems/windows/">Windows</a> containers. Use <code>mcr.microsoft.com/<a href="/operating-systems/windows/">windows</a>/servercore:ltsc2022</code> as the base.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: What if the agent connects but shows "Error: Unable to retrieve information"?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: The agent's Docker socket may be inaccessible. Check that <code>/var/run/docker.sock</code> is mounted correctly.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: How many agents can one Portainer server manage?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: There's no hard limit. Practical limits depend on server resources β 100+ agents are common.</p>
</div></details>
---
*Portainer Agent setup is covered in the [DodaTech Portainer Administration course](https://dodatech.com/courses/portainer).*
β Previous
How to Fix Common Poetry Installation Errors
Next β
Fix Portainer App Template β Custom Template Not Appearing
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro