Docker Community Forums

Share and learn in the Docker community.

Mosquitto deployment compose

I have a couple of issues deploying mosquitto, I hope someone can shine a light on it.
I am using docker compose and want to add the container to a custom network (called mynetwork)
Besides that, I want to use the password file I have created (mosquitto.passwd)
What happens when I deploy the container with docker-compose:

  • The container runs, but not in the defined network.
    it mentions Stack: docker, dont know why.
    No ports are published, although I have defined some ports to be published.

I have a mosquitto.conf file and a mosquitto.passwd file which I would like to deploy automatically using my docker-compose script, how do I do that ?

Below my compose script and config file

compose file:

version: '3.8'
services:
######################################
# Mosquitto (mqtt)
######################################
  mqtt:
    image: eclipse-mosquitto:2.0
    hostname: mqtt
    container_name: mqtt
    restart: always
    volumes:
      - /docker/mqtt/data:/mosquitto/data
      - /docker/mqtt/config:/mosquitto/config
      - /docker/mqtt/log:/mosquitto/log
    ports:
      - "1883:1883"
    network_mode: "mynetwork"
    environment:
      - TZ=Europe/Amsterdam  
    command: "mosquitto -c /mosquitto/config/mosquitto.conf"

config file:

persistence true
persistence_location /docker/mqtt/data/
log_dest file /docker/mqtt/log/mosquitto.log

## Authentication ##
allow_anonymous true
password_file /docker/mqtt/mosquitto.passwd

When something doesn’t work as expected, read the documentation again and again until you see what your mistake was. Do this even if you are sure you did everything right because there is a good chance you are just not able to notice the difference when you subconsciously don’t want to believe that could be the solution. network_mode is not for setting a network name. It is a “mode” not a name. You have networks to set network names.

1 Like