Skip to content

Commit affd839

Browse files
Document running tox within a Docker container (#2923)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 610bef5 commit affd839

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

docs/changelog/1035.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document running tox within a Docker container.

docs/faq.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,45 @@ Access full logs
306306

307307
If you want to access the full logs you need to write ``-q`` and ``-v`` as
308308
individual tox arguments and avoid combining them into a single one.
309+
310+
Running within a Docker container
311+
---------------------------------
312+
313+
If you want to run tox within a Docker container you can use `31z4/tox <https://hub.docker.com/r/31z4/tox>`_.
314+
This Docker image neatly packages tox along with common build dependencies (e.g., ``make``, ``gcc``, etc) and currently
315+
`active CPython versions <https://devguide.python.org/versions/#status-of-python-versions>`_. See more details in
316+
its `GitHub repository <https://github.com/31z4/tox-docker>`_.
317+
318+
The recommended way of using the image is to mount the directory that contains your tox configuration files and your
319+
code as a volume. Assuming your project is within the current directory of the host, use the following command to run
320+
tox without any flags:
321+
322+
.. code-block:: shell
323+
324+
docker run -v `pwd`:/home/tox/tests -it --rm 31z4/tox
325+
326+
Because an entry point of the image is ``tox``, you can easily pass subcommands and flags:
327+
328+
.. code-block:: shell
329+
330+
docker run -v `pwd`:/home/tox/tests -it --rm 31z4/tox run-parallel -e black,py311
331+
332+
Note, that the image is configured with a working directory at ``/home/tox/tests``.
333+
334+
If you want to install additional Python versions/implementations or Ubuntu packages you can create a derivative image.
335+
Just make sure you switch the user to ``root`` when needed and switch back to ``tox`` afterwards:
336+
337+
.. code-block:: Dockerfile
338+
339+
FROM 31z4/tox
340+
341+
USER root
342+
343+
RUN set -eux; \
344+
apt-get update; \
345+
DEBIAN_FRONTEND=noninteractive \
346+
apt-get install -y --no-install-recommends \
347+
python3.12; \
348+
rm -rf /var/lib/apt/lists/*
349+
350+
USER tox

0 commit comments

Comments
 (0)