Open philipobrien opened 5 years ago
Please see https://github.com/eclipse/mosquitto/issues/1452, that may be the same issue as the one I am having (with a workaround)
I don't think it is as the same. For me I can see in the mosquitto logs Saving in-memory database to /mosquitto/data/mosquitto.db
, and then within the mosquitto container mosquitto.db
is being written to /mosquitto/data
, but although this is mapped to a local dir (/home/ubuntu/data/mosquitto-data
) nothing appears in the local dir
Ah this is indeed strange - I also have all kind of docker files on my server and mapping works the way you describe.
Maybe you could try to map /mosquitto
to /home/ubuntu/data/mosquitto
to have all the directories in one mapping and see whether you find the file there?
had a similar issue. In my case stopping and removing the container did the trick
@philipobrien
After struggling with things mentioned in this issue. And like those mentioned in #1452 I arrived at something that works for me:
# docker-compose.yml
version: '3.7'
services:
broker:
image: eclipse-mosquitto
restart: always
ports:
- "1883:1883"
- "9001:9001"
volumes:
- type: bind
source: ./mosquitto/config/mosquitto.conf
target: /mosquitto/config/mosquitto.conf
- type: bind
source: ./mosquitto/data/
target: /var/lib/mosquitto/
# mosquitto.conf
persistence true
persistence_location /var/lib/mosquitto/
And making sure on the host that I ran:
sudo chown 1883:1883 ./mosquitto/data
Doing all this and it seemed to work for me.
I struggled with it too. After a lot of experimenting, I found the solution was quite simple. Just create the three directories:
mkdir -p ./containers/mosquitto/{config,data,log}
Then in ./containers/mosquitto/config/mosquitto.conf
comes:
port 1883
listener 9001
protocol websockets
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
The Docker Compose file then becomes:
version: '3.7'
services:
mosquitto:
image: eclipse-mosquitto
container_name: mosquitto
restart: always
ports:
- "1883:1883"
- "9001:9001"
volumes:
- ./containers/mosquitto/config:/mosquitto/config
- ./containers/mosquitto/data:/mosquitto/data
- ./containers/mosquitto/log:/mosquitto/log
- /etc/localtime:/etc/localtime:ro
user: "1000:1000"
You need to specify the config, data and log directory separately. Also note the user: "1000:1000"
at the end, which is needed so the container can write to the data and log directories. Replace this by the user ID and group ID of your current user.
After this, you have data persistence and logs on the host machine.
Worked! Why does it require them to be separate mounts?
I'm spinning the image up with compose as follows
with the following set in the config file
but although
/mosquitto/data
is indeed being written to in the container (i.e.mosquitto.db
being created there), nothing is appearing in the synced volume on the host. Inspecting the container mounts showsI can't figure it out because I'm following the same process for mounting volumes for postgres, mongo, and elasticsearch and they are all working as expected