Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mosquitto running inside Docker container can't find config file (which definitely exists inside the Docker container in the correct location) #2960

Closed
magnus-bakke opened this issue Dec 1, 2023 · 1 comment

Comments

@magnus-bakke
Copy link

magnus-bakke commented Dec 1, 2023

No matter what I do, Mosquitto can't seem to find the config file that definitely exists. Everything is apparently configured according to the instructions here: https://hub.docker.com/_/eclipse-mosquitto

Mosquitto is running in a Docker container based on python:3.11.6-bullseye. Docker is running on a Windows host. It's executed from Python (Popen) with this command: "mosquitto -c /mosquitto/config/mosquitto.conf --verbose"

Mosquitto version: 2.0.11.

Here is an excerpt from the logs of the program. Notice that we are confirming the existence of the file, the perms, etc., but Mosquitto is still using the default config and starting in local only mode:

Starting Mosquitto Eclipse as a service.

Does config file (/mosquitto/config/mosquitto.conf) exist? True

PERMS OF CONFIG FILE:
-rwxrwxrwx 1 1883 1883 40475 Nov 28 02:41 /mosquitto/config/mosquitto.conf

CONTENTS OF CONFIG FILE:
# Config file for mosquitto
#
# See mosquitto.conf(5) for more information.
# ...

Running: mosquitto -c /mosquitto/config/mosquitto.conf --verbose

1701447361: mosquitto version 2.0.11 starting
1701447361: Using default config.
1701447361: Starting in local only mode. Connections will only be possible from clients running on this machine.

I have confirmed:

  • The file exists at /mosquitto/config/mosquitto.conf inside the Docker container
  • The file has Linux line endings
  • The file exists on container startup (tried both mapping in a volume and COPYing in the Dockerfile)
  • The file has 777 permissions (more appropriate permissions don't work either)
  • The file contains these settings:
allow_anonymous true
listener 1883
persistence true
persistence_location /mosquitto/data/

Mosquitto is executed using Python:

command = ["mosquitto", "-c", "/mosquitto/config/mosquitto.conf"]
broker_process = Popen(command, shell=True, text=True)

If I run it directly from a start.sh script (same command: mosquitto -c /mosquitto/config/mosquitto.conf), it works, but we have to run it from a Python script for various reasons.

@magnus-bakke magnus-bakke changed the title Mosquitto running inside Docker container can't find config file (which definitely exists) Mosquitto running inside Docker container can't find config file (which definitely exists inside the Docker container in the correct location) Dec 1, 2023
@magnus-bakke
Copy link
Author

It turns out running Popen with shell=True was preventing the passing of arguments somehow, so the -c argument was ignored. Removing shell=True makes it find the config file.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant