diff --git a/README.md b/README.md index 4f330f80..48850a37 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ Works on Linux, macOS and Windows, for Python 3.8 and above. pip install python-on-whales ``` +See +for instructions on installing Docker/Podman. + ## Some cool examples Start by doing diff --git a/docs/template/docker_client.md b/docs/template/docker_client.md index b012e5fc..20708cae 100644 --- a/docs/template/docker_client.md +++ b/docs/template/docker_client.md @@ -3,7 +3,8 @@ {{autogenerated}} -# Sub-commands +## Sub-commands + * [`docker.buildx`](sub-commands/buildx.md) * [`docker.compose`](sub-commands/compose.md) * [`docker.config`](sub-commands/config.md) @@ -23,7 +24,7 @@ * [`podman.pod`](sub-commands/pod.md) -# Other commands +## Other commands They're actually aliases @@ -60,7 +61,7 @@ They're actually aliases * [`docker.wait`](sub-commands/container.md#python_on_whales.components.container.cli_wrapper.ContainerCLI.wait) -# About multithreading and multiprocessing +## About multithreading and multiprocessing Behind the scenes, Python on whales calls the Docker command line interface with subprocess. The Python on whales client does not store any intermediate state so it's safe @@ -92,7 +93,7 @@ In the end, unless you use this type of logic in your code, Python-on-whales is safe to use with multithreading and multiprocessing. -# The Docker/Podman CLI +## The Docker/Podman CLI Python-on-whales needs the Docker or Podman CLI to work (unlike docker-py). Most of the time, users already have the CLI installed on their machines. It's possible to @@ -112,7 +113,7 @@ Previously, when using python-on-whales, the Docker CLI was downloaded automatic this functionality was removed under . -# Handling an unavailable client +### Handling an unavailable client Trying to use Python-on-whales when it cannot find or download a Docker client binary will trigger a `python_on_whales.ClientNotFoundError`. You can use a try-except around diff --git a/docs/template/user_guide/running_python_on_whales_inside_a_container.md b/docs/template/user_guide/running_python_on_whales_inside_a_container.md index 6e0fd5a1..2cd49e18 100644 --- a/docs/template/user_guide/running_python_on_whales_inside_a_container.md +++ b/docs/template/user_guide/running_python_on_whales_inside_a_container.md @@ -15,7 +15,7 @@ Let's give you the code example, and we'll explain afterwards where is the magic ### Example -We want to run this small Python script. It uses python-on-whales. We'll call it `main.py` +We want to run this small Python script. It uses python-on-whales. We'll call it `main.py`. ```python # main.py @@ -38,21 +38,24 @@ Next to this `main.py`, make a `Dockerfile`. # Dockerfile FROM python:3.9 -RUN pip install python-on-whales -RUN python-on-whales download-cli +RUN wget https://download.docker.com/linux/static/stable/x86_64/docker-27.3.1.tgz -O /tmp/docker-27.3.1.tgz +RUN tar -C /tmp -xzf /tmp/docker-27.3.1.tgz +RUN cp /tmp/docker/docker /usr/local/bin/docker # install docker buildx, this step is optional RUN mkdir -p ~/.docker/cli-plugins/ -RUN wget https://github.com/docker/buildx/releases/download/v0.6.3/buildx-v0.6.3.linux-amd64 -O ~/.docker/cli-plugins/docker-buildx +RUN wget https://github.com/docker/buildx/releases/download/v0.17.1/buildx-v0.17.1.linux-amd64 -O ~/.docker/cli-plugins/docker-buildx RUN chmod a+x ~/.docker/cli-plugins/docker-buildx # install docker compose, this step is optional RUN mkdir -p ~/.docker/cli-plugins/ -RUN wget https://github.com/docker/compose/releases/download/v2.0.1/docker-compose-linux-x86_64 -O ~/.docker/cli-plugins/docker-compose +RUN wget https://github.com/docker/compose/releases/download/latest/docker-compose-linux-x86_64 -O ~/.docker/cli-plugins/docker-compose RUN chmod a+x ~/.docker/cli-plugins/docker-compose -COPY ./main.py /main.py -CMD python /main.py +RUN pip install python-on-whales +RUN mkdir /app +COPY ./main.py /app/main.py +CMD python3 /app/main.py ``` We're all set! Let's run this Python script, without having Python installed on the system! @@ -98,7 +101,7 @@ compose version: Docker Compose version v2.0.0-rc.2 The main magic here is the sharing of the docker socket between the host and the container. This is done with the `-v /var/run/docker.sock:/var/run/docker.sock`. -With this option, the container can have access to the docker API. But it still needs the binary client in Go. -Download it in the dockerfile with `python-no-whales download-cli`. You can then optionally install buildx and compose. +With this option, the container can have access to the docker API. But it still needs the binary client, +which is downloaded using `wget`, along with optionally installing the buildx and compose plugins. Then you're good to go! Simple as that. \ No newline at end of file diff --git a/tests/python_on_whales/components/test_pod.py b/tests/python_on_whales/components/test_pod.py index 41697be7..d8a2805f 100644 --- a/tests/python_on_whales/components/test_pod.py +++ b/tests/python_on_whales/components/test_pod.py @@ -194,7 +194,7 @@ def test_create_share_arg(podman_client: DockerClient): assert output == "1" with podman_client.pod.create(pod_name, share=["pid", "ipc"]) as pod: pod.start() # start the infra container (PID 1) - assert pod.shared_namespaces == ["pid", "ipc"] + assert set(pod.shared_namespaces) == {"pid", "ipc"} output = podman_client.container.run( "ubuntu", ["readlink", "/proc/self"], pod=pod )