Skip to content

Instantly share code, notes, and snippets.

@shantanoo-desai
Created October 23, 2023 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shantanoo-desai/1634f3206ce486707a4c047bcc043c4c to your computer and use it in GitHub Desktop.
Save shantanoo-desai/1634f3206ce486707a4c047bcc043c4c to your computer and use it in GitHub Desktop.
Forwards Compatibililty for Eclipse Mosquitto MQTT Broker with Docker Init Containers and Docker Compose v2 include
# Docker Init Container
# Alpine Container that changes the File Permissions and Ownership
# of the mounted configuration files
# NOTE: WILL ALWAYS BE EXECUTED BEFORE THE MAIN MOSQUITTO CONTAINER
# NOTE: WILL ALSO PERMANENTLY CHANGE THE FILE PERMISSIONS/OWNERSHIP ON HOST
services:
mosquitto_init:
image: docker.io/alpine:3.18
container_name: mosquitto_init
command: sh -c "chmod 0400 -R /config/ && chown -R 1883:1883 /config/"
volumes:
- ./mosquitto/mosquitto.conf:/config/mosquitto_conf
- ./mosquitto/users:/config/mosquitto_users
# Main Compose File for Mosquitto MQTT Broker
# The `mosquitto` service is dependent on the `mosquitto_init` service
# to execute correctly / completely and load the changed configuration
# files into the current container using `volumes_from`
include:
- docker-compose.mosquitto-init.yml
services:
mosquitto:
image: docker.io/eclipse-mosquitto:2.0.18
container_name: mqtt_fwd_compatible
entrypoint: mosquitto -c /config/mosquitto_conf
depends_on:
mosquitto_init:
condition: service_completed_successfully
security_opt:
- "no-new-privileges=true"
volumes_from:
- mosquitto_init
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
# under mosquitto/mosquitto.conf
# EXAMPLE CONFIG FILE WITH ADAPTED PATHS/ FILES
# MQTT Port Listener
listener 1883
protocol mqtt
# Authentication
allow_anonymous false
password_file /config/mosquitto_users
# Logging Configuration
log_timestamp true
log_type all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment