driver failed programming external connectivity on endpoint redis : Bind for 0.0.0.0:6379 failed: port is already allocated

Viewed 4561

I'm trying to run

/usr/bin/docker run --rm -v /var/data/redis:/data -v /var/data/conf/redis.conf:/usr/local/etc/redis/redis.conf --name redis -p 6379:6379 redis:5.0.3-alpine3.9

but I get:

/usr/bin/docker: Error response from daemon: driver failed programming external connectivity on endpoint redis (f16f19b7727a710fb6c96be566dac66ce26282982960d97faa28861c24fcf2fb): Bind for 0.0.0.0:6379 failed: port is already allocated.

When I try to check the ports used with netstat, I get:

[root@artik ~]# netstat -nlpute | grep 6379
tcp6       0      0 :::6379                 :::*                    LISTEN      0          14384       2471/docker-proxy

I have no docker containers running right now.

I don't understand this issue, what should I do ?

[root@artik ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
4 Answers

Steps I had to take to get everything working:

sudo service docker stop
sudo rm /var/lib/docker/network/files/local-kv.db
sudo service docker start
docker system prune

And then try again.

From your netstat output its clear that there is one process holding port 6379

[root@artik ~]# netstat -nlpute | grep 6379
tcp6       0      0 :::6379                 :::*                    LISTEN      0          14384       2471/docker-proxy

docker-proxy processes are created when you do port forwarding in docker run which is true in your case -p 6379:6379.

For more info on docker-proxy check this out.

I suspect that you earlier ran a redis container which used port 6379, but that container was not properly deleted which kept process docker-proxy running and hence you got port is already allocated

Hope this helps.

As DannyMoshe suggested for anyone else.

Try this before you potentially mess up your whole setup::

sudo service docker stop
sudo service docker start

remove the ports - ... in the docker-compose file and let it assign by itself. or change the port mapping in the host from 6379:6379 to 6378:6379 that worked for me. Before doing this you may need to clear already started containers. docker rm -f $(docker ps -a -q)

Related