#MQTT on docker

1 messages · Page 1 of 1 (latest)

ivory kite
#

setting up the mqtt container didn't fixed it. The container is not starting properly. I don't have a clue why, because it shows no logs. Has anyone an idea how to troubleshoot this?

weary merlin
#

Docker compose?

#

I have two of those installs and they work without a problem.
Did you add the .conf file for the mqtt config?

ivory kite
#

Yes, I use docker-compose

keen pilot
#

Mapping files directly with docker is always tricky, create the files and folders before starting the container

#

Docker will create the files as folders by default if they don't exist

weary merlin
#

plus 1 to what @keen pilot said.

ivory kite
#

I created a conf/ a data/ and a log/ folder and mapped them as a volume in my docker-compose.yaml file. The mosquitto.conf file is in the conf/ folder.

keen pilot
#

Is it actually a file?

#

Or a folder?

#

Also if you start the container without any mappings, does the error change?

ivory kite
#

It's a file.

weary merlin
#

This is what I have:
`#### mosquitto.conf file contents - Dont give spaces between lines ####
persistence true
persistence_location /mosquitto/data/

log_dest file /mosquitto/log/mosquitto.log
log_timestamp true

listener 1883
allow_anonymous true`

ivory kite
#

Here is my config:

#

`persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883

Authentication

allow_anonymous true
password_file /mosquitto/data/password.txt`

#

Starting it without any mappings didn't change anything

weary merlin
#

Could you just replace yours with mine and restart? AFAIR, the conf file does not like blank lines and you may have one?

#

Just guessing here; the mqtt container has never been an issue - it's such a simple spin. BTW, permissions can be an issue too...like with all things Linux.

ivory kite
#

Same issue with your config

#

But sudo docker run -it --name mosquitto2 -p 1883:1883 eclipse-mosquittois working

#

Permissions was also a thing I was thinking of. The data/ and the log/ directory were always changed to 1883 for owner and group

weary merlin
#

So, and I am no Linux pro, I use host networking - not sure if that is right or wrong but that is how I have always used it.

#

`version: '3'

services:

mosquitto:
container_name: mosquitto
image: eclipse-mosquitto
restart: always
network_mode: host
volumes:
- /home/mosquitto/data:/mosquitto/data
- /home/mosquitto/log:/mosquitto/log
- /home/mosquitto/config:/mosquitto/config:ro
- /etc/localtime:/etc/localtime:ro`

ivory kite
#

year networking on docker is also not clear to me yet.

#

With your yaml i get this errors chown: /mosquitto/config/mosquitto.conf: Read-only file system chown: /mosquitto/config: Read-only file system

weary merlin
#

I am afraid that is the extent of my Linux mqtt knowledge. Sorry.

ivory kite
#

No problem. Thank you for your time and your support

keen pilot
#

A good tips is to do this :

  1. Make your user part of the docker group (no need for sudo docker commands)
  2. Make the top level folder of your persistant volumes group owned by docker group
  3. Make the subfolders automatically inherit group membership

that way you always have access to edit files \ folders and there shouldn't be any permission errors spinning up stuff either

#

sudo usermod -aG docker $USER

#

sudo chgrp docker /docker/persistant/folder/top/directory

#

sudo chmod g+s /docker/persistant/folder/top/directory

#

I forexample do /mnt/ssdz1/appsmount as my top directory, with a seperate dataset (zfs specific) which creates a new folder under that top level, eg /mnt/ssdz1/appsmount/mosquitto

#

and all my docker compose files lives in /mnt/ssdz1/docker-compose

#

I then have aliases for calling said compose files, like alias dcmedia="docker compose -f /mnt/ssdz1/docker-compose/media-compose.yaml"

#

which means I just do dcmedia pull to pull said compose and dcmedia up -d to create them

ivory kite
#

Thank you for the explanation. I changed the permission and group and added my user to the docker group, but the error stays the same. Everytime I create the container with docker-compose the user and group for the config/, data/ and log/ folder are changed back to 1883

keen pilot
#

That is the permissions it expects

#

ls -ll /your/persistent/path

ivory kite
#

drwxr-xr-x 2 1883 1883 4096 Aug 11 10:41 config drwxr-xr-x 2 1883 1883 4096 Aug 11 10:48 data drwxr-xr-x 2 1883 1883 4096 Aug 11 10:48 log

keen pilot
#

And on the config folder?

ivory kite
#

-rw-r--r-- 1 1883 1883 227 Aug 11 10:41 mosquitto.conf

keen pilot
#

No execute permission on it for owner tom

#

sudo chmod 755 mosquitto.conf

#

Shouldn't matter, but strange

#

Currently it is 644 if math is correct

#

Eh, 644 should be fine

#
Linux mirai 5.10.0-16-amd64 #1 SMP Debian 5.10.127-1 (2022-06-30) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Aug 11 10:47:50 2022 from 192.168.1.173
eirikz@mirai ~ % ls -ll /mnt/ssdz1/appsmount/mosquitto
total 16
drwxrwxr-x 2 1883             1883   4 May  7 15:27 data
drwxrwxr-x 2 root systemd-timesync   3 Jul 14  2021 log
-rwxrwxr-- 1 1883             1883 400 Jan 31  2022 mosquitto.conf
-rwxrwxr-- 1 1883             1883 116 Jul 14  2021 mosquitto.passwd
-rwxrwxr-- 1 1883 systemd-timesync   1 May  4 09:55 mosquitto.pid
eirikz@mirai ~ %
ivory kite
#

Year strange, but it doesn't fix it. I read so many tutorials how to run MQTT with docker-compose. That is no rocket science. 🤯

keen pilot
#

I had issues too because it created the files as directories

#

Once I figured that out

#

I have never had issues

#

Only container I've had issues with too

ivory kite
#

It seems to be a problem with the mosquitto.conf file.

#

Just changed it to

#

`# persistence true

persistence_location /mosquitto/data/

log_dest file /mosquitto/log/mosquitto.log`

#

this worked 1660211528: mosquitto version 2.0.14 starting 1660211528: Config loaded from /mosquitto/config/mosquitto.conf. 1660211528: Starting in local only mode. Connections will only be possible from clients running on this machine. 1660211528: Create a configuration file which defines a listener to allow remote access. 1660211528: For more details see https://mosquitto.org/documentation/authentication-methods/ 1660211528: Opening ipv4 listen socket on port 1883. 1660211528: Opening ipv6 listen socket on port 1883. 1660211528: mosquitto version 2.0.14 running

keen pilot
#

Woo