Port already allocate when trying to re-start container

Hello community,

two weeks ago I had to stop a Thingsboard/Postgres container, due to maintenance of the Linux server. Now I try to start it again, but get the error:

  • docker inspect returns:

0.0.0.0:80->9090/tcp

  • docker container start returns:

Error response from daemon: driver failed programming external connectivity on endpoint prod_ec-thingsboard-prod_1 (c54cbc3ba0139d0e1f937d6e4a99540e0da2a078313cce7fda6a2f42fccd790a): Bind for 0.0.0.0:8080 failed: port is already allocated

Do I understand correctly, that the host at port 0.0.0.0:8080 was in the meantime allocated for a different process? I tried netstat -nlp , and indeed the Local Address 0.0.0.0:8080 port has a Foreign Address 0.0.0.0:* and state “listen”. But how can I identify by which process it is allocated?

Many thanks

We usually need the following information to understand the issue:

  1. What platform are you using? Windows, Linux or macOS? Which version of the operating systems? In case of Linux, which distribution?

  2. How did you install Docker? Sharing the platform almost answers it, but only almost. Direct links to the followed guide can be useful.

  3. On debian based Linux, the following commands can give us some idea and recognize incorrectly installed Docker:

    docker info
    docker version
    

    Review the output before sharing and remove confidential data if any appears (public IP for example)

    dpkg -l 'docker*' | grep '^ii'
    snap list docker
    

    When you share the outputs, always format your posts according to the following guide: How to format your forum posts

Please also share how you create the container (either docker run command, or the content of a compose file`).

  1. I am using Linux version 5.10.0-18-amd64 #1 SMP Debian 5.10.140-1

  2. Docker was installed prior my time… (see no.3)

  3. dpkg -l 'docker*' | grep '^ii' returns
    ii docker-compose 1.25.0-1 all Punctual, lightweight development environments using Docker
    and

    ii docker.io 20.10.5+dfsg1-1+deb11u2 amd64 Linux container runtime

Hopefully this information is adequately formatted. The content of the container .yaml file is:

cat docker-compose.yml :

version: '2.2'

services:

  ec-thingsboard-prod:

    restart: always

    image: "thingsboard/tb-postgres"

    ports:

      - "8080:9090"

      - "1883:1883"

      - "7070:7070"

      - "5683-5688:5683-5688/udp"

    environment:

      TB_QUEUE_TYPE: in-memory

      SQL_TTL_TS_TS_KEY_VALUE_TTL: 7884009

    volumes:

      - /data/prod/data:/data

      - /data/prod/log:/var/log/thingsboard

Congrats, you found an ancient server with Linux Kernel from 14-Dec-2020 and Docker 20.10.5 from 2021-03-02 :wink: Maybe some bugs have been fixed since then. Not to mention security improvements.

docker ps shows you which containers use which ports.

netstat -tulpn shows you which ports are used on host.

To extend what @bluepuma77 already said:

You are using the docker.io package which is maintained by the Ubuntu developers, not Docker Inc. I understand that you were not the one who installed it, but the package itself another reason why it is harder to help you with this issu today.

You are also using Docker Compose v1, which was discontinued long time ago.

You either typed the output incorrectly or you forgot to share some details as you showed tht the port is forwarded from the host from port 80, but you get an error message about port 8080.

I also don’T see that you shared the output of

Is it because you got nothing or you forgot to run that? Whe you have port issues after a restart, that can also be because you have another Docker daemon and a container is running on that port. In this case I think you would have had an error message about the docker socket instead of ports, but the output could still be important.

Or if there is no other docker daemon, it could be a systemd service that was just stopped before but not disabled, so it started a porcess on a port before Docker started..

docker info and docker version outputs would also help

1 Like

@rimelek: since a Debian kernel matching the one from Debian 11 is used, most likely a derivate of Debian Bullseye is used, which to my knowledge does not use snap.

Note: the official docker repository for bullseye is still maintained. Installation instructions to install vanilla docker: Debian | Docker Docs

If you want to stick to your current, non-vanilla docker, installation, there is not much we can do for you. The support channel for the docker package you are using is the Debian community. You would need to ask them for assistance.

It indicates a process on the host already binds this port on at least one of the ips.

The output of sudo netstat -tlpn | grep ":8080 " should show which process binds the port.
If the process is docker-proxy, I am curious if it works after rebooting the vm.

There used to be a kernel bug that sometimes had race conditions when releasing/binding ports, though your kernel version shouldn’t be affected anymore (see: When the blue whale sinks)

1 Like

Snap could be installed on Debian 9 and above, but probably not installed by default, so snap Docker is not likely to be installed accidentally. Thanks for bringing it to my attention.

1 Like
  • Indeed we use Debian bullseye (version 11). I guess that is why snap list docker doesn’t work here
  • It was my mistake about the port, docker inspect returns: “9090/tcp”: {“HostIp”: “0.0.0.0”,“HostPort”: “8080”}
  • It appears as is an older container, who should be stopped, started running again. This blocked my container somehow. Now the Thingsboard is active again.

I will research whether a vanilla docker installation is possible on our server.

Thank you for now for all this insight

Thank you

  • Thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.