From 2f3eb33c19229fc96dc6420defe0eecb34aa873f Mon Sep 17 00:00:00 2001 From: f18m Date: Fri, 6 Mar 2026 23:38:30 +0100 Subject: [PATCH 1/5] Add version 2.1.2 --- modules/mqtt/tests/test_mosquitto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mqtt/tests/test_mosquitto.py b/modules/mqtt/tests/test_mosquitto.py index 63ce7fcd9..29ce1443f 100644 --- a/modules/mqtt/tests/test_mosquitto.py +++ b/modules/mqtt/tests/test_mosquitto.py @@ -2,7 +2,7 @@ from testcontainers.mqtt import MosquittoContainer -VERSIONS = ["1.6.15", "2.0.18"] +VERSIONS = ["1.6.15", "2.0.18", "2.1.2"] @pytest.mark.parametrize("version", VERSIONS) From cb1c85c8f1f210e2fa6b13f1b612226d035584eb Mon Sep 17 00:00:00 2001 From: f18m Date: Fri, 6 Mar 2026 23:56:42 +0100 Subject: [PATCH 2/5] add fix for mosquitto higher than 2.1.1 --- modules/mqtt/testcontainers/mqtt/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/mqtt/testcontainers/mqtt/__init__.py b/modules/mqtt/testcontainers/mqtt/__init__.py index 54a2d87ac..18a1e1917 100644 --- a/modules/mqtt/testcontainers/mqtt/__init__.py +++ b/modules/mqtt/testcontainers/mqtt/__init__.py @@ -121,6 +121,10 @@ def start(self, configfile: Optional[str] = None) -> Self: # default config file configfile = Path(__file__).parent / MosquittoContainer.CONFIG_FILE self.with_volume_mapping(configfile, "/mosquitto/config/mosquitto.conf") + # since version 2.1.1 - 2026-02-04, which fixed a PUID/PGID issue, the container needs to write to the data directory, + # so we need to map it to a volume + self.with_volume_mapping("mosquitto_data", "/data", mode="rw") + # if self.password: # # TODO: add authentication # pass From 3a77f81ebefb1b71daeb5599b930764a9f0859e0 Mon Sep 17 00:00:00 2001 From: f18m Date: Sat, 7 Mar 2026 00:18:33 +0100 Subject: [PATCH 3/5] fix config file to use non-root user and have listener appear before protocol --- .../testcontainers-mosquitto-default-configuration.conf | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/mqtt/testcontainers/mqtt/testcontainers-mosquitto-default-configuration.conf b/modules/mqtt/testcontainers/mqtt/testcontainers-mosquitto-default-configuration.conf index 13728cec0..b3c67048f 100644 --- a/modules/mqtt/testcontainers/mqtt/testcontainers-mosquitto-default-configuration.conf +++ b/modules/mqtt/testcontainers/mqtt/testcontainers-mosquitto-default-configuration.conf @@ -1,7 +1,6 @@ # see https://mosquitto.org/man/mosquitto-conf-5.html -protocol mqtt -user root +listener 1883 log_dest stdout allow_anonymous true @@ -14,7 +13,4 @@ log_timestamp_format %Y-%m-%d %H:%M:%S persistence true persistence_location /data/ -listener 1883 -protocol mqtt - sys_interval 1 From 700d1a81d31de9b4f02235df2a2e19364d3395e0 Mon Sep 17 00:00:00 2001 From: f18m Date: Sat, 7 Mar 2026 23:54:43 +0100 Subject: [PATCH 4/5] f --- modules/mqtt/tests/test_mosquitto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mqtt/tests/test_mosquitto.py b/modules/mqtt/tests/test_mosquitto.py index 29ce1443f..1e058103c 100644 --- a/modules/mqtt/tests/test_mosquitto.py +++ b/modules/mqtt/tests/test_mosquitto.py @@ -2,7 +2,7 @@ from testcontainers.mqtt import MosquittoContainer -VERSIONS = ["1.6.15", "2.0.18", "2.1.2"] +VERSIONS = ["1.6.15", "2.0.18", "2.1.2-alpine"] @pytest.mark.parametrize("version", VERSIONS) From 210719e42a72202e9ba7ded1ba119827eb99a1d7 Mon Sep 17 00:00:00 2001 From: f18m Date: Mon, 23 Mar 2026 23:28:48 +0100 Subject: [PATCH 5/5] Add support for tmpfs mounting --- core/testcontainers/core/container.py | 13 +++++++++++++ modules/mqtt/testcontainers/mqtt/__init__.py | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/testcontainers/core/container.py b/core/testcontainers/core/container.py index cf61a85bf..4fc80e4f9 100644 --- a/core/testcontainers/core/container.py +++ b/core/testcontainers/core/container.py @@ -82,6 +82,8 @@ def __init__( for vol in volumes: self.with_volume_mapping(*vol) + self.tmpfs: dict[str, str] = {} + self.image = image self._docker = DockerClient(**(docker_client_kw or {})) self._container: Optional[Container] = None @@ -198,6 +200,7 @@ def start(self) -> Self: ports=cast("dict[int, Optional[int]]", self.ports), name=self._name, volumes=self.volumes, + tmpfs=self.tmpfs, **{**network_kwargs, **self._kwargs}, ) @@ -270,6 +273,16 @@ def with_volume_mapping(self, host: Union[str, PathLike[str]], container: str, m self.volumes[str(host)] = mapping return self + def with_tmpfs_mount(self, container_path: str, size: Optional[str] = None) -> Self: + """Mount a tmpfs volume on the container. + + :param container_path: Container path to mount tmpfs on (e.g., '/data') + :param size: Optional size limit (e.g., '256m', '1g'). If None, unbounded. + :return: Self for chaining + """ + self.tmpfs[container_path] = size or "" + return self + def get_wrapped_container(self) -> "Container": return self._container diff --git a/modules/mqtt/testcontainers/mqtt/__init__.py b/modules/mqtt/testcontainers/mqtt/__init__.py index 18a1e1917..854ec21f8 100644 --- a/modules/mqtt/testcontainers/mqtt/__init__.py +++ b/modules/mqtt/testcontainers/mqtt/__init__.py @@ -122,8 +122,8 @@ def start(self, configfile: Optional[str] = None) -> Self: configfile = Path(__file__).parent / MosquittoContainer.CONFIG_FILE self.with_volume_mapping(configfile, "/mosquitto/config/mosquitto.conf") # since version 2.1.1 - 2026-02-04, which fixed a PUID/PGID issue, the container needs to write to the data directory, - # so we need to map it to a volume - self.with_volume_mapping("mosquitto_data", "/data", mode="rw") + # so we mount it as tmpfs for better performance in tests + self.with_tmpfs_mount("/data") # if self.password: # # TODO: add authentication