Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs references to download-cli #639

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Works on Linux, macOS and Windows, for Python 3.8 and above.
pip install python-on-whales
```

See <https://gabrieldemarmiesse.github.io/python-on-whales/docker_client/#the-dockerpodman-cli>
for instructions on installing Docker/Podman.

## Some cool examples

Start by doing
Expand Down
11 changes: 6 additions & 5 deletions docs/template/docker_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,7 +24,7 @@
* [`podman.pod`](sub-commands/pod.md)


# Other commands
## Other commands

They're actually aliases

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -112,7 +113,7 @@ Previously, when using python-on-whales, the Docker CLI was downloaded automatic
this functionality was removed under <https://github.com/gabrieldemarmiesse/python-on-whales/pull/633>.


# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!
Expand Down Expand Up @@ -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.
2 changes: 1 addition & 1 deletion tests/python_on_whales/components/test_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Loading