I have a problem with running eclipse image under docker. Particular with the access to the log folder.
Compose file:
version: '2.1'
services:
mqtt:
image: eclipse-mosquitto:latest
container_name: "mqtt2"
restart: always
ports:
- 1883:1883
- 9001:9001
volumes:
- /volume1/apps/configs/mqtt/data:/mosquitto/data
- /volume1/apps/configs/mqtt/config:/mosquitto/config:ro
- /volume1/apps/configs/mqtt/logs:/mosquitto/log
environment:
- TZ=Europe/Berlin
And the docker logs:
1544689704: Error: Unable to open log file /mqtt/logs/mosquitto.log for writing.
1544689704: Error: Unable to open log file /mqtt/logs/mosquitto.log for writing.
1544689705: Error: Unable to open log file /mqtt/logs/mosquitto.log for writing.
1544689706: Error: Unable to open log file /mqtt/logs/mosquitto.log for writing.
1544689708: Error: Unable to open log file /mqtt/logs/mosquitto.log for writing.
1544689710: Error: Unable to open log file /mqtt/logs/mosquitto.log for writing.
This is folder permission:
drwx------+ 5 myUser users 4096 Dec 12 23:42 .
drwx------+ 9 myUser users 4096 Dec 12 21:12 ..
drwxrwxrwx 2 root users 4096 Dec 12 23:22 config
drwxrwxrwx 2 root users 4096 Dec 12 21:12 data
d---------+ 2 root root 4096 Dec 12 23:42 logs
I have also tried creating the mosquitto.log file ahead, but no success.
When I run the same command with
mqtt:
image: toke/mosquitto:latest
everything is fine. But I would like to run eclipse image.
P.S. I dont have mosquitto user in my system added.
I'm also seeing this issue after upgrading my docker container (using eclipse-mosquitto:latest). Running on Docker 18.09.0 CE and Rancher 1.6.21 on CentOS Linux 7 (3.10.0).
I have the following volumes mapped to my host as read-write:
/mosquitto/config
/mosquitto/data
/mosquitto/log
I've tried deleting the log file and starting the container, but it still throws the same error.
Have a check on uid and gid mapping between host and container.
Read/Write access is not trivial if this do not match.
The uid that the image used for the "mosquitto" user had to be set to a fixed value. In previous versions it was set to the next available uid, which was almost certain to clash with an existing system uid, potentially causing permission problems. The uid:gid it now uses is fixed at 1883:1883, so you should be able to update your permissions to match. Apologies for the inconvenience.
Thanks. I'm using Rancher and NFS volumes, so I had to chown 1883:1883 <volume-name> -R on the NFS server to make sure my permissions were correct. Once I did that, the upgraded container started up fine.
I have the same issue. I have created a mosquitto user with uid and gid 1883.
id mosquitto
uid=1883(mosquitto) gid=1883(mosquitto) groups=1883(mosquitto)
cd /srv/mosquitto
chown -R 1883:1883 config/ data/ log/
ls -al
drwxrwx--- 2 mosquitt mosquitt 4096 Feb 16 14:49 config
drwxrwx--- 2 mosquitt mosquitt 4096 Feb 16 14:39 data
drwxrwx--- 2 mosquitt mosquitt 4096 Feb 17 20:35 log
as root user>
docker run -it -p 1883:1883 -p 9001:9001 -e PGID=1883 -e PUID=1883 -v /srv/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf -v /srv/mosquitto/data -v /srv/mosquitto/log eclipse-mosquitto
1550395157: Error: Unable to open log file /srv/mosquitto/log/mosquitto.log for writing.
I have tried with root 0:0 as well. But I get the same error. I have tried without the -e PGID and -e PUID flag, and I get the same error. I have tried giving the log file global read write permissions (777) and I get the same error. How do I get this running?
@nilathj Try:
cd log
sudo touch mosquitto.log
sudo chmod o+w ./mosquitto.log
sudo chown 1883:1883 /srv/mosquitto/log -R
No same error:
/srv/mosquitto/log# ls -al
total 8
drwxrwx--- 2 mosquitt mosquitt 4096 Feb 20 19:57 .
drwxr-xr-x 5 1001 1001 4096 Feb 16 17:08 ..
-rw-r--rw- 1 mosquitt mosquitt 0 Feb 20 19:57 mosquitto.log
/srv/mosquitto/log# docker run -it -p 1883:1883 -p 9001:9001 -v /srv/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.
conf -v /srv/mosquitto/data -v /srv/mosquitto/log eclipse-mosquitto
1550653867: Error: Unable to open log file /srv/mosquitto/log/mosquitto.log for writing.
I'm running, Alpine Linux v3.9 as host OS. Docker version 18.09.1-ce. I am running docker as root.
2961 root 56:17 /usr/bin/dockerd -p /run/docker.pid
If I don't specify an external config, this container runs fine and I can connect to it using an external mqtt client.
I have the same problem and the mentioned solution also did not work for me. Any further hints?
same problem here too.
1552421249: Saving in-memory database to /mosquitto/data/mosquitto.db.
1552421249: Error saving in-memory database, unable to open /mosquitto/data/mosquitto.db.new for writing.
1552421249: Error: Permission denied.
I'll try a few things as suggested in this thread
for me adding the --user parameter fixed this issue.
same problem
services:
mqtt:
image: eclipse-mosquitto
container_name: mqtt
user: 1883:1883
environment:
- PUID=1883
- PGID=1883
it's a permissions thing. In my case I use
mosquitto:
container_name: mosquitto
image: eclipse-mosquitto
user: "1000:996"
ports:
- 1883:1883
volumes:
- /etc/localtime:/etc/localtime:ro
- ${USERDIR}/docker/mosquitto/config:/mosquitto/config:ro
- ${USERDIR}/docker/mosquitto/data:/mosquitto/data
- ${USERDIR}/docker/mosquitto/log:/mosquitto/log
restart: always
network_mode: host
and the docker group in /etc/group (id 996) has the user 'mosquitto'
it's a permissions thing. In my case I use
mosquitto: container_name: mosquitto image: eclipse-mosquitto user: "1000:996" ports: - 1883:1883 volumes: - /etc/localtime:/etc/localtime:ro - ${USERDIR}/docker/mosquitto/config:/mosquitto/config:ro - ${USERDIR}/docker/mosquitto/data:/mosquitto/data - ${USERDIR}/docker/mosquitto/log:/mosquitto/log restart: always network_mode: hostand the docker group in /etc/group (id 996) has the user 'mosquitto'
indeed, its a permissions issue. But even though I replicate your configuration and adding the user mosquitto to docker group, doesn't fix my problem. I've tried almost everything so far
@jtomasrl also make sure user (with id 1883 in your example) is also in the docker group and the permissions are set correctly on the file and directory (g+w)
@proddy the user 1883 is "mosquitto"
This is my actual configuration and whatever I do, it doesn't work
id mosquitto
uid=1883(mosquitto) gid=1883(mosquitto) groups=1883(mosquitto),996(docker)
ls -l
-rwxrwxrwx 1 mosquitto mosquitto 2 May 5 11:47 mosquitto.log
cat docker-compose.yml
version: "3"
services:
mqtt:
image: eclipse-mosquitto
container_name: mqtt
user: "1883:996"
cat mosquitto.conf
persistence true
persistence_location /mqtt/data/
log_dest file /mqtt/log/mosquitto.log
user mosquitto
the log directory in your compose file is /mosquitto/log and in your .conf its /mqtt/log/. I think they should at least match.
Also I don't use the id of mosquitto (1883) but 1000 which is the owner of my docker
I was just using a placeholder for the directory, but they match. I tried using mi id 1000 (owner of docker) without luck
@nilathj Try:
cd log sudo touch mosquitto.log sudo chmod o+w ./mosquitto.log sudo chown 1883:1883 /srv/mosquitto/log -R
It finally worked for me using @nilathj 's approach.
The key was not to create a new mosquitto user on the host system, so the below search returns no results:
sudo cat /etc/passwd | grep 1883
Instead I just gave owner rights to 1883 UID/GID for the mqtt root folder on the host machine where all data, logs and configs are stored. And also gave rwx rights.
sudo chown -R 1883:1883 /opt/mqtt
sudo chmod -R 770 /opt/mqtt
So the result is:
drwxrwx--- 5 1883 1883 4096 Jun 15 15:05 mqtt/
I assumed that a user / group has to exist on a system in order to be granted ownership but it seems that I have to research this further :)
I ran into the same problem myself today.
My setup is running mosquitto in docker on a Synology nas.
For mosquitto, I created the following mqqt-folders:
/volume1/docker/mosquitto/config
/volume1/docker/mosquitto/data
/volume1/docker/mosquitto/log
Starting the image fails with the error message that mosquitto is unable to open the log file for writing.
After running the following command:
sudo chown -R 1883:1883 /volume1/docker/mosquitto
and restarting mosquitto, everything works like a charm.
Note: I did not create a new user for mosquitto on the nas.
use of directives:
-e GUID and -e GUID do not help much, there is an error that the package does not include it at all.
Each time files with group number and user ID 1883 are created
>/mosquitto/log# ls -l
total 4
-rwxrwxrwx 1 1883 1883 45 Oct 23 19:18 mosquitto.log
the only solution was:
mkdir -p '/volume2/docker-data/mosquitto/'
mkdir -p '/volume2/docker-data/mosquitto/config/'
mkdir -p '/volume2/docker-data/mosquitto/log'
mkdir -p '/volume2/docker-data/mosquitto/data'
next:
complete the file:
/volume2/docker-data/mosquitto/config/mosquitto.conf:
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
then run:
docker run -d \
--name = MOSQUITTO1 \
--restart = always \
-p 1883: 1883 \
-p 9001: 9001 \
///// -e PGID = 100 \ <- delete it, its my Moquitto local user GroupID: how to show in ssh?: > id mosquitto
//// - e PUID = 1031 \ <- delete its my Mosquitto local user UserID
////-e TZ = Europe/Warsaw \
-v /etc/localtime:/etc/localtime:ro \ <- it's more universal than -e TZ...
-v '/ volume2/docker-data/mosquitto/config': '/mosquitto/config': ro \
-v '/ volume2/docker-data/mosquitto/log': '/mosquitto/log' \
-v '/ volume2/docker-data/mosquitto/data': '/mosquitto/data' \
eclipse-mosquitto: latest
next:
chmod a + rwx '/volume2/docker-data/mosquitto/data' -R
chmod a + rwx '/volume2/docker-data/mosquitto/log' -R
and a few minutes after the server starts again:
chmod a + rwx '/volume2/docker-data/mosquitto/data' -R
chmod a + rwx '/volume2/docker-data/mosquitto/log' -R
so that a normal user can read these files from Synology
so the mistake is that PID / GUID 1883 is always used maniacally, regardless of what I specified in the startup file
Tried all of the above. Still not working.
I've changed the ownership of the volume's directories and it works.
sudo chown -hR $MOSQUITO_USER $DIRECTORY
In my case:
sudo chown -hR mosquitto ./mosquitto
I ran into the same problem myself today.
My setup is running mosquitto in docker on a Synology nas.
For mosquitto, I created the following mqqt-folders:
/volume1/docker/mosquitto/config /volume1/docker/mosquitto/data /volume1/docker/mosquitto/logStarting the image fails with the error message that mosquitto is unable to open the log file for writing.
After running the following command:
sudo chown -R 1883:1883 /volume1/docker/mosquittoand restarting mosquitto, everything works like a charm.
Note: I did not create a new user for mosquitto on the nas.
After trying several things from this thread, this is what worked for me.
Welcome eclipse/mosquitto!
You are invited to access PLAFYA's Customer Self Service Portal
By accessing this portal, you can track your requests online,
access knowledge base and join the community forums.
ACCEPT THE INVITATION
Your user name is [email protected] | You can also click here to accept the invitation
Thank you, PLAFYA Administrator
This email has been sent to you(reply+ald3pf7ooqgt5ccufsuwha54yjsf5evbnhhbor5yfy@reply.github.com) by wizyty@afya.pl from PLAFYA. Please contact the sender(wizyty@afya.pl) for any clarifications.
After a while I got it to work.
This are the steps that made the trick:
My yaml:
mosquitto:
image: eclipse-mosquitto
hostname: mosquitto
container_name: mosquitto
ports:
- 1883:1883
- 9001:9001
volumes:
- /opt/appdata/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
- /opt/appdata/mosquitto/data:/mosquitto/data
- /opt/appdata/mosquitto/log:/mosquitto/log
restart: always
environment:
- PUID=${PUID}
- PGID=${PGID}
I use the same user/group for all the containers:
$ echo ${PUID}
1001
$ echo ${PGID}
1001
$ id 1001
uid=1001(dockeradmin) gid=1001(dockeradmin) groups=1001(dockeradmin)
My problem was permissions like most of the people in this tread, so I ran this command:
$ chmod -R 777 /opt/appdata/mosquitto/
After all that, restarted the container and no more errors.
Praktyka Lekarskia AFYA, https://afya.pl
Witaj eclipse/mosquitto!
Otrzymali艣my Pa艅stwa wiadomo艣膰 e-mail,
a nasz System informatyczny automatycznie nada艂 jej numer.
W dalszym kontakcie - prosimy nie zmienia膰 tytu艂u wiadomo艣ci
i pos艂ugiwa膰 si臋 w艂a艣nie tym numerem
Nie oznacza to, 偶e wiadomo艣膰 zosta艂a przeczytana, a jedynie dostarczona.
Odpowiadamy zwykle w ci膮gu 4 dni roboczych.
T臋 wiadomo艣膰 otrzymacie Pa艅stwo jednokrotnie (nie wy艣lemy jej ponownie nawet przy prawid艂owym dostarczeniu kolejnych wiadomo艣ci e-mail), dlatego zapraszamy do odwiedzenia Naszego Centrum Pomocy Customer Self Service Portal
Wchodz膮c tam, mo偶ecie 艣ledzi膰 swoje wiadomo艣ci i odpowiedzi na nie w trybie rzeczywistym, uzyskacie tak偶e dost臋p do bazy wiedzy i b臋dziecie mogli do艂膮czy膰 do for贸w spo艂eczno艣ciowych.
ZAAKCEPTUJ ZAPROSZENIE
W ka偶dym przypadku w膮tpliwo艣ci
zapraszamy do kontaktu z nasz膮 rejestracj膮 pod numerem telefonu
+48 71 88 08 555
Pa艅stwa nazwa U偶ytkownika to: [email protected] | Mo偶ecie r贸wnie偶 klikn膮膰 tutaj kliknij tutaj, aby zaakceptowa膰 to zaproszenie automatycznie.
Dzi臋kujemy za kontakt. Zesp贸艂 AFYA.pl
This email has been sent to you(reply+ald3pf4yrxoh4w65li77r2v5g7z3hevbnhhbor5yfy@reply.github.com) by wizyty@afya.pl from Praktyka Lekarska AFYA - POMOC. Please contact the sender(wizyty@afya.pl) for any clarifications.
Most helpful comment
I ran into the same problem myself today.
My setup is running mosquitto in docker on a Synology nas.
For mosquitto, I created the following mqqt-folders:
/volume1/docker/mosquitto/config /volume1/docker/mosquitto/data /volume1/docker/mosquitto/logStarting the image fails with the error message that mosquitto is unable to open the log file for writing.
After running the following command:
sudo chown -R 1883:1883 /volume1/docker/mosquittoand restarting mosquitto, everything works like a charm.
Note: I did not create a new user for mosquitto on the nas.