You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changed Dockerfile and default service definition to support
`MOSQUITTO_BASE` argument which defaults to `eclipse-mosquitto:latest`.
This means users will not have to edit `.templates/mosquitto/Dockerfile`
in order to pin to a specific version.
Also added image metadata fields (`build-args` and `based-on`) and
unset environment variables not needed outside Dockerfile scope.
Documentation updated to explain new structure and how to pin.
Signed-off-by: Phill Kelley <[email protected]>
Copy file name to clipboardExpand all lines: docs/Containers/Mosquitto.md
+93-37Lines changed: 93 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,14 +86,30 @@ $ docker-compose up -d
86
86
87
87
`docker-compose` reads the *Compose* file. When it arrives at the `mosquitto` fragment, it finds:
88
88
89
-
```
89
+
```yaml
90
90
mosquitto:
91
91
container_name: mosquitto
92
-
build: ./.templates/mosquitto/.
92
+
build:
93
+
context: ./.templates/mosquitto/.
94
+
args:
95
+
- MOSQUITTO_BASE=eclipse-mosquitto:latest
93
96
…
94
97
```
95
98
96
-
The `build` statement tells `docker-compose` to look for:
99
+
Note:
100
+
101
+
* Earlier versions of the Mosquitto service definition looked like this:
102
+
103
+
```yaml
104
+
mosquitto:
105
+
container_name: mosquitto
106
+
build: ./.templates/mosquitto/.
107
+
…
108
+
```
109
+
110
+
The single-line `build` produces *exactly* the same result as the four-line `build`, save that the single-line form does not support [pinning Mosquitto to a specific version](#mosquitto-version-pinning).
111
+
112
+
The `./.templates/mosquitto/.` path associated with the `build` tells `docker-compose` to look for:
97
113
98
114
```
99
115
~/IOTstack/.templates/mosquitto/Dockerfile
@@ -103,11 +119,10 @@ The `build` statement tells `docker-compose` to look for:
103
119
104
120
The *Dockerfile* begins with:
105
121
122
+
```dockerfile
123
+
ARG MOSQUITTO_BASE=eclipse-mosquitto:latest
124
+
FROM $MOSQUITTO_BASE
106
125
```
107
-
FROM eclipse-mosquitto:latest
108
-
```
109
-
110
-
> If you need to pin to a particular version of Mosquitto, the *Dockerfile* is the place to do it. See [Mosquitto version pinning](#mosquitto-version-pinning).
111
126
112
127
The `FROM` statement tells the build process to pull down the ***base image*** from [*DockerHub*](https://hub.docker.com).
113
128
@@ -144,7 +159,7 @@ You *may* see the same pattern in Portainer, which reports the *base image* as "
144
159
145
160
> Whether you see one or two rows depends on the version of `docker-compose` you are using and how your version of `docker-compose` builds local images.
Under the original IOTstack implementation of Mosquitto (just "as it comes" from *DockerHub*), the service definition expected the configuration files to be at:
The path `/mosquitto/log/mosquitto.log` is an **internal** path. When this style of logging is active, you inspect Mosquitto's logs using the **external** path like this:
Replace «username» and «password» with appropriate values, then execute the command. For example, to create the username "hello" with password "world":
299
314
300
-
```
315
+
```bash
301
316
$ docker exec mosquitto mosquitto_passwd -b /mosquitto/pwfile/pwfile hello world
@@ -423,15 +438,15 @@ There are several ways to reset the password file. Your options are:
423
438
424
439
If you do not have the Mosquitto clients installed on your Raspberry Pi (ie `$ which mosquitto_pub` does not return a path), install them using:
425
440
426
-
```
441
+
```bash
427
442
$ sudo apt install -y mosquitto-clients
428
443
```
429
444
430
445
#### test: *anonymous access is prohibited*
431
446
432
447
Test **without** providing credentials:
433
448
434
-
```
449
+
```bash
435
450
$ mosquitto_pub -h 127.0.0.1 -p 1883 -t "/password/test" -m "up up and away"
436
451
Connection Refused: not authorised.
437
452
Error: The connection was refused.
@@ -445,7 +460,7 @@ Note:
445
460
446
461
Test with credentials
447
462
448
-
```
463
+
```bash
449
464
$ mosquitto_pub -h 127.0.0.1 -p 1883 -t "/password/test" -m "up up and away" -u hello -P world
450
465
$
451
466
```
@@ -458,14 +473,14 @@ Note:
458
473
459
474
Prove round-trip connectivity will succeed when credentials are provided. First, set up a subscriber as a background process. This mimics the role of a process like Node-Red:
@@ -499,7 +514,7 @@ The agent is invoked 30 seconds after the container starts, and every 30 seconds
499
514
* Subscribes to the same broker for the same topic for a single message event.
500
515
* Compares the payload sent with the payload received. If the payloads (ie time-stamps) match, the agent concludes that the Mosquitto broker (the process running inside the same container) is functioning properly for round-trip messaging.
Portainer's *Containers* display contains a *Status* column which shows health-check results for all containers that support the feature.
505
520
@@ -545,7 +560,7 @@ Notes:
545
560
* If you enable authentication for your Mosquitto broker, you will need to add `-u «user»` and `-P «password»` parameters to this command.
546
561
* You should expect to see a new message appear approximately every 30 seconds. That indicates the health-check agent is functioning normally. Use <kbd>control</kbd>+<kbd>c</kbd> to terminate the command.
You can customise the operation of the health-check agent by editing the `mosquitto` service definition in your *Compose* file:
551
566
@@ -636,47 +651,88 @@ Your existing Mosquitto container continues to run while the rebuild proceeds. O
636
651
637
652
The `prune` is the simplest way of cleaning up. The first call removes the old *local image*. The second call cleans up the old *base image*. Whether an old *base image* exists depends on the version of `docker-compose` you are using and how your version of `docker-compose` builds local images.
638
653
639
-
### Mosquitto version pinning
654
+
### <aname="mosquitto-version-pinning"> Mosquitto version pinning </a>
640
655
641
-
If you need to pin Mosquitto to a particular version:
656
+
If an update to Mosquitto introduces a breaking change, you can revert to an earlier know-good version by pinning to that version. Here's how:
642
657
643
-
1. Use your favourite text editor to open the following file:
658
+
1. Use your favourite text editor to open:
644
659
645
660
```
646
-
~/IOTstack/.templates/mosquitto/Dockerfile
661
+
~/IOTstack/docker-compose.yml
647
662
```
648
663
649
-
2. Find the line:
664
+
2. Find the Mosquitto service definition. If your service definition contains this line:
650
665
651
-
```
652
-
FROM eclipse-mosquitto:latest
666
+
```yaml
667
+
build: ./.templates/mosquitto/.
653
668
```
654
669
655
-
3. Replace `latest`with the version you wish to pin to. For example, to pin to version 2.0.10:
670
+
then replace that line with the following four lines:
656
671
672
+
```yaml
673
+
build:
674
+
context: ./.templates/mosquitto/.
675
+
args:
676
+
- MOSQUITTO_BASE=eclipse-mosquitto:latest
657
677
```
658
-
FROM eclipse-mosquitto:2.0.10
678
+
679
+
Notes:
680
+
681
+
* The four-line form of the `build` directive is now the default for Mosquitto so those lines may already be present in your compose file.
682
+
* Remember to use spaces, not tabs, when editing compose files.
683
+
684
+
3. Replace `latest` with the version you wish to pin to. For example, to pin to version 2.0.13:
685
+
686
+
```yaml
687
+
- MOSQUITTO_BASE=eclipse-mosquitto:2.0.13
659
688
```
660
689
661
690
4. Save the file and tell `docker-compose` to rebuild the local image:
The new *local image* is built, then the new container is instantiated based on that image. The `prune` deletes the old *local image*.
670
700
671
-
Note:
701
+
5. Images built in this way will always be tagged with "latest", as in:
672
702
673
-
* As well as preventing Docker from updating the *base image*, pinning will also block incoming updates to the *Dockerfile* from a `git pull`. Nothing will change until you decide to remove the pin.
703
+
```bash
704
+
$ docker images iotstack_mosquitto
705
+
REPOSITORY TAG IMAGE ID CREATED SIZE
706
+
iotstack_mosquitto latest 8c0543149b9b About a minute ago 16.2MB
707
+
```
708
+
709
+
You may find it useful to assign an explicit tag to help you remember the version number used for the build. For example:
710
+
711
+
```bash
712
+
$ docker tag iotstack_mosquitto:latest iotstack_mosquitto:2.0.13
713
+
$ docker images iotstack_mosquitto
714
+
REPOSITORY TAG IMAGE ID CREATED SIZE
715
+
iotstack_mosquitto 2.0.13 8c0543149b9b About a minute ago 16.2MB
716
+
iotstack_mosquitto latest 8c0543149b9b About a minute ago 16.2MB
717
+
```
718
+
719
+
You can also query the image metadata to discover version information:
0 commit comments