Error starting userland proxy: listen tcp4 0.0.0.0:50028: bind: address already in use

Error response from daemon: Cannot restart container : driver failed programming external connectivity on endpoint :(f102f1a4d9c7): Error starting userland proxy: listen tcp4 0.0.0.0:54343: bind: address already in use

It states clearly “address already in use”, so the port is already used by another process. What do you expect now by posting the error without any context at all?

we are using docker-compose.yml file for stop/start the containers as it’s intermittent issue we see this error every time for different containers , we have updated docker/docker-compose version but issue still persist

On Linux, try netstat -tulpn to see open ports and listening processes.

We have checked with above command it shows as below time_wait & close_wait. but we don’t see any process associated with the port.

[hostname]$ netstat -taulpn | grep 51723
tcp6 0 0 :10050 :51723 TIME_WAIT -
[hostname]$

The order is local-address foreign-address, so it might just be an outgoing connection from that port to your server, with the port number by chance.

Are you exposing the port from your container and also from your Docker Desktop VM? Did you run the command on host and in VM?

yes we are exposing the ports , we have run the command on host , what would be the cause & fix

Please execute the command @bluepuma77 shared as root user, so we can see which process binds the port.

@meyay it’s intermittent issue so we are not seeing now , will share with you once i see but i have mentioned port is not getting release when we are restarting containers via docker compose.yml when we do netstat it shows TIME_WAIT or CLOSE_WAIT so we have to wait for port to close once it’s closed properly then we start the containers

can anyone pls help ?

How can we help when you have a process on host already using the port? It doesn’t really seem like a Docker problem.

my question is why it’s not releasing the port , usually when we down the container via compose file it should release the ports ,due to this our jenkins jobs are failing since it’s restarting the containers every 4 hrs

I have read the topic now, and we should clarify some details. You created your topic in the Docker Desktop for Linux category. @bluepuma77 mentioned Docker Desktop, but it was not clear to me whether you actualy run Docker Desktop or just Docker CE on Linux without Desktop. So which is the case?

I also saw in your first post that the problem is with restarting the container. In that case, the container could start once so another running app on the same port shouldn’t be the problem, I agree with that, but if you indeed use Docker Desktop, the userand proxy is in the virtual machine, where I doubt that you run any other process. I saw and also experienced some issues with used ports on a macOS host which runs Docker Desktop, because the port forwarding from the host into the virtual machine just didn’t happen and the container could start inside the VM. But that’s a different issue.

Please, share the output of docker info and docker version.

If it is really just about conflicts related to compose project down and up, you can make your script wait until the project resources are actually removed:

docker compose --project-name ${PROJECT_NAME} --file compose.yml down
resource_types="container network"
for type in ${resource_types}; do
  until [ -z "$(docker $type ls --filter label=com.docker.compose.project=${PROJECT_NAME})" ]; do
    sleep 1
  done
done

If you want the volumes to be deleted as well, add the -v argument after down and add volume to the resource_types

1 Like

docker version
Client: Docker Engine - Community
Version: 24.0.6
API version: 1.43
Go version: go1.20.7
Git commit: ed223bc
Built: Mon Sep 4 12:35:25 2023
OS/Arch: linux/amd64
Context: default

Server: Docker Engine - Community
Engine:
Version: 24.0.6
API version: 1.43 (minimum version 1.12)
Go version: go1.20.7
Git commit: 1a79695
Built: Mon Sep 4 12:34:28 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.7.3
GitCommit: 7880925980b188f4c97b462f709d0db8e8962aff
runc:
Version: 1.1.11
GitCommit: v1.1.11-0-g4bccb38
docker-init:
Version: 0.19.0
GitCommit: de40ad0