danyolgiax
danyolgiax

Reputation: 13086

Mosquitto broker won't restart with Docker on Raspberry reboot

I installed Mosquitto broker with Docker on Raspbian this way:

docker pull eclipse-mosquitto

docker run -d -p 1883:1883 -p 9001:9001 --name=mosquitto eclipse-mosquitto --restart=always

When I reboot the Raspberry, the container seems that is not running and I cannot connect to it. If I try to run it again I get:

docker: Error response from daemon: Conflict. The container name 
"/mosquitto" is already in use by container 
"3187ab53a3a2067b9d6ce0sa647a8d90cb52485f5540ca4eacad1c4e662ffa9d". You have 
to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.

So I need to remove it

docker rm -f mosquitto

and restart it again.

What I miss?

Upvotes: 0

Views: 2516

Answers (1)

ErikMD
ErikMD

Reputation: 14723

Docker Engine prevents two containers from having the same name.

So if you run twice the command like this:

docker run -d -p 1883:1883 -p 9001:9001 --name=mosquitto eclipse-mosquitto
docker stop mosquitto  # simulates your reboot
docker run -d -p 1883:1883 -p 9001:9001 --name=mosquitto eclipse-mosquitto

Then the second attempt will fail, as you noticed.

Actually, I guess that you had put the option --restart=always in the wrong place. (More precisely, the arguments given after the image name are not seen as Docker CLI options, they are provided to the entrypoint: docker run [OPTIONS] image-name [ARGUMENTS])

Could you try this (and reboot)?

docker run -d -p 1883:1883 -p 9001:9001 --name=mosquitto --restart=always eclipse-mosquitto

Otherwise, you could just as well do:

docker start eclipse-mosquitto

after a docker stop or a reboot that wouldn't succeed in restarting the container.

Upvotes: 2

Related Questions