Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent wont start after update "Unable to retrieve local agent IP address" #203

Trufax opened this issue Aug 5, 2021 · 9 comments


Copy link

Trufax commented Aug 5, 2021


i use watchtower to update my containers but the Portainer agent keeps to have issues when updated.
Whenever watchtower updates the container, it keeps restarting with the following error message:

agent_1 | 2021/08/05 12:22:25 [ERROR] [main,docker] [message: Unable to retrieve local agent IP address] [error: Error: No such container: 6c9fd4504fb5]

And i use the following compose file:

    image: portainer/portainer-ce
      # REQUIRED: Should be equal to the service name prefixed by "tasks." when
      # deployed inside an overlay network
      - "9000:9000"
      - "8000:8000"
      - portainer_data:/data
    restart: unless-stopped
    image: v2tec/watchtower
      - /var/run/docker.sock:/var/run/docker.sock
    command: portainer_agent_1 portainer_watchtower_1
    restart: unless-stopped

I can fix it by manually running docker-compose down and than up again but this defeats the whole purpose of the automatic updates.


Copy link

I had the same problem around 3 months.

Copy link

Trufax commented Aug 7, 2021

I guess you still have the issue now or did you solve it somehow ?

Copy link

I still have this issue, I just recreate it every time

Copy link

Maybe set the watchtower to monitor only mode for the portainer-agent container.

Add the label com.centurylinklabs.watchtower.monitor-only to portainer-agent

Copy link

jackman815 commented Aug 8, 2021

# docker inspect fc8934356e2d | grep Hostname
            "Hostname": "c77766f05c0e",

I found the problem is about the watchtower, it clones the container configs included hostname when upgrading the container.

When upgrade/re-create the container, by default the docker daemon will assign a new hostname to the container and update internal dns, but the watchtower won't update the container hostname after the container upgrade so the agent will try to look up the old hostname and it would be getting nxdomain result by docker internal dns.

return os.Hostname()

// CreateMockContainerWithConfig creates a container substitute valid for testing
func CreateMockContainerWithConfig(id string, name string, image string, running bool, restarting bool, created time.Time, config *dockerContainer.Config) container.Container {
	content := types.ContainerJSON{
		ContainerJSONBase: &types.ContainerJSONBase{
			ID:    id,
			Image: image,
			Name:  name,
			State: &types.ContainerState{
				Running:    running,
				Restarting: restarting,
			Created: created.String(),
			HostConfig: &dockerContainer.HostConfig{
				PortBindings: map[nat.Port][]nat.PortBinding{},
		Config: config,
	return *container.NewContainer(
			ID: image,

Copy link

jackman815 commented Aug 8, 2021

I try to add the --hostname arg to start the container, waiting for the next agent's update and check the working status.

My config:

docker run -d \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /var/lib/docker/volumes:/var/lib/docker/volumes \
  -v /:/host \
  -v portainer_agent_data:/data \
  --network="bridge" \
  --hostname portainer_edge_agent \
  --restart always \
  -e EDGE=1 \
  -e EDGE_ID= \
  -e EDGE_KEY= \
  --name portainer_edge_agent \

Copy link

Trufax commented Aug 8, 2021

Thanks for sharing. I added

hostname: portaineragent
container_name: portaineragent

to my compose file, lets see if this works with the next update.

Copy link

Trufax commented Oct 12, 2021

i can confirm that setting the hostname and the container_name fixed the issue for me. Portainer agent is now updating fine with watchtower.

@Trufax Trufax closed this as completed Oct 12, 2021
Copy link

Was able to fix this from Portainer by just stopping continer > Duplicate / Edit > scroll down to advanced container settings > Network > make hostname field match container name > Deploy Container

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

3 participants