How to fix docker driver failed programming external connectivity on endpoint webserver?


This blog post will address how to fix the docker issue EADDRINUSE (PORT or ADDRESS already in use). Here is a little error snapshot which I have taken from my docker container which I was aiming to run on port 1313 but unfortunately the port is already occupied by some other process.

1docker: Error response from daemon: driver failed programming external connectivity on endpoint 
2webserver (kdudfuyfndekdur6h8e3b271db180ffbee0a56caeskdhfudeu363fbc02ea805101df21e): Error starting 
3springboot proxy: Bind for 0.0.0.0:1313: unexpected error (Failure EADDRINUSE).

Root Cause - The exact root cause of this docker error is the PORT conflict. There could be two reasons behind this issue -

  1. Either there is some background process that is already occupying the PORT 1313
  2. You are trying to start one more docker container using the same PORT 1313

How to fix - docker driver failed programming external connectivity on endpoint web server?

  1. Start the container on different port
  2. Find and kill the process already running on same port
  3. Reset docker network by removing network files located at /var/lib/docker/network/files/local-kv.db
  4. Restart Docker service
  5. Conclusion

1. Start the container on a different port

The first obvious solution would be to start your new docker image on another port. So if you have a possibility to start your docker container on another port then go for it.

I had this issue on my port 1313

Here is an example of how to start the container on another port e.g. 1414 -

1docker run -p 1414:1414 -t rahulwagh17/jhooq-docker-demo:jhooq-docker-demo 

Here is my dockerfile -

1FROM openjdk:8-jdk-alpine
2ARG JAR_FILE=build/libs/*.jar
3COPY ${JAR_FILE} app.jar
4ENTRYPOINT ["java","-jar","/app.jar"]

If you are using the docker-compose.yaml then you need to make port change into your docker-compose.yaml -

Here is my docker-compose.yaml with port 1414 -

 1version: '3'
 2
 3services:
 4  jhooq-springboot-container:
 5    image: jhooq-spring-boot-docker-compose:1
 6    build:
 7      context: ./
 8      dockerfile: Dockerfile
 9    volumes:
10      - /data/jhooq-springboot-container
11    ports:
12      - "1414:1414" 

Using the above approach you can avoid the port conflict and fix the docker driver failed programming external connectivity on endpoint web server issue.


2. Find and kill the process already running on the same port

The second approach would be to find another process that is already occupying the PORT 1313 and kill the process.

(*Note - Be careful when you kill the other process because you might stop some critical process in your system or production environment. So always check it through before killing any process.)

2.1 Use the following command to find the process running on port 1313

1lsof -i :1313 

2.2 Kill the process running on PID

Now you know the process by PID which is running on port 1313.

Use the following bash command to kill the process by PID -

1kill -9 2944 

3. Reset docker network by removing network files located at /var/lib/docker/network/files/local-kv.db

If the previous two steps(Step-1,Step-2) does not help you to fix the issue then I would recommend you to reset the docker network setting

The possible reason could be that docker has failed to reset the network setting causing the docker driver to fail programming external connectivity on endpoint webserver

To fix this you need to delete the local-kv.db file. To delete the file you can use the following command -

1rm /var/lib/docker/network/files/local-kv.db

In case if you get permission denied issue then use sudo.


4. Restart Docker service

If the previous steps(Step-1,Step-2,Step-3) does not help you much in troubleshooting your issue and you did not find any possible reason then restarting docker service would be a better option.

Use the following command to restart the docker service -

1sudo service docker restart 

5. Conclusion

The majority of the errors which occur due to PORT conflict (EADDRINUSE) can be resolved by searching the process which has already occupied the PORT.

Also do not rush to kill the process which is already occupying your desired port because it may result in unforeseen issues in a production environment.