MQTT Docker wont start

I converted to Docker on a NUC Ubuntu 16.04 from RPi 3.
I manage to get home assistant working with a few other problems but the main one is MQTT
It just wont start. and keeps restarting.

Here is my docker_compose.yaml file

version: '3'
services:
  portainer:
    container_name: portainer
    image: portainer/portainer
    volumes:
      - /home/$USER/docker/portainer_data:/data
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "9000:9000"

  mqtt:
    image: eclipse-mosquitto:latest
    container_name: "MQTT"
    restart: always
    volumes:
      - /home/$USER/docker/mqtt/data:/mqtt/data
      - /home/$USER/docker/mqtt/config:/mqtt/config
      - /home/$USER/docker/mqtt/log:/mqtt/log
    network_mode: "host"
    ports:
      - "1883:1883"
      - "9001:9001" 

All folders have been sudo chmod -R 777 /home/$USER/docker/mqtt/data

And this is the mosquitto.conf

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /home/cameron/docker/mqtt/data/

user homeassistant

# Port to use for the default listener.
port 1883


log_dest file /home/cameron/docker/mqtt/log/mosquitto.log
log_dest stdout

This is the sudo docker ps

CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS                          PORTS                                                              NAMES
bfd2ed266933        homeassistant/home-assistant   "python -m homeassis…"   6 minutes ago       Up 6 minutes                    0.0.0.0:8123->8123/tcp, 0.0.0.0:51826->51826/tcp                   home-assistant
6536950e5b24        eclipse-mosquitto:latest       "/docker-entrypoint.…"   6 minutes ago       Restarting (3) 53 seconds ago    

mqtt.yaml in Homeassistant…

  broker: 127.0.0.1
  port: 1883
  discovery: true
  client_id: home-assistant-nuc
  keepalive: 60
  username: !secret mqtt_user
  password: !secret mqtt_password

Any help please…

Shouldn‘t the paths in mosquito.conf point to /mqtt/data and /mqtt/log ?

Yes. /home/Cameron doesn’t exist in the docker container

Thanks @docbobo and @flamingm0e

I change the user to cameron and made a mqtt user to cameron .
I also put the docker mqtt IP address into the broker: 172.19.0.5

It all works now.

I am having a similar problem right now with a very similar hardware setup and docker-compose file. I think that I can attempt the solution listed above but I have a couple of questions especially as it relates to “user”.

I didn’t see in any setup documentation how to setup the username and password as it shows in the configuration.yaml file. Is there an extra step that I missed? Can this be left blank without a user/password or is this not recommended?

Lastly in cameron’s last reply, where was the change made to user “cameron”? As part of the user/password? or in a config somewhere?

If you only access HA from your home network, and that is secure, setting a username and password for MQTT isn’t necessary.

If you regularly have guests on your home network that you don’t particularly trust, adding a username and password gives a small amount of additional protection, but since they would be able to snoop your network traffice and decode the username, this really is not significant.

Obviously, if you can access MQTT from outside your home network, you need a username, password and encrypted traffic to your broker.

You need to add username and password configuration to both the Mosquitto configuration files and HA’s configuration.yaml. There is a mosquitto_passwd program to manage the mosquitto side.