Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Swarm Init Fails: Address already in use

I've been going through the docker tutorial at https://docs.docker.com/v17.12/get-started/part3/#take-down-the-app-and-the-swarm and am up to the part where we're setting up our initial docker swarm.

I had this working at first, but then had to reconcile differences between a snap install docker and apt install docker on my system. Following this, when I try to run docker swarm init I'm told:

Error response from daemon: manager stopped: failed to listen on remote API address: listen tcp 0.0.0.0:2377: bind: address already in use

I have no other docker images or services running, so I'm fine killing or deleting anything, but I can't seem to figure out how to clear up this port so that I can initialize a new swarm.

Is there a way to either A) Kill the running swarm, or B) List the available swarms so that I can join it and then kill it from there as a swarm master?

Thanks!

like image 678
Robert Townley Avatar asked Nov 29 '18 20:11

Robert Townley


1 Answers

Seems like you have installed docker from both snap/apt and you must uninstall one of the two (one is running in swarm mode and the docker client is connecting to the one that isn't).

To find the process running swarm use the following:

sudo ss --tcp --listening --processes --numeric | grep ":2377"

This will list the processes listening on the port 2377, on my case i find:

LISTEN   0      128     *:2377     *:*    users:(("dockerd",pid=1229,fd=24))

Now using the pid you can find the process location:

sudo readlink -f /proc/1229/exe

If the process comes from a snap then you know that you must stop it and remove the snap so it only leaves the inastallation from apt-get (or viseversa if you want to keep the snap installation).

like image 143
codestation Avatar answered Oct 14 '22 14:10

codestation