containers / containers/podman-py

Image build doesn't use caches

Open
#528 6 comments 1 reaction 0 assignees View on GitHub
bug good first issue
Dominant language
Python
Stars
381
Forks
140
Avg merge
5h 30m
Merged PRs (30d)
1

Description

When I repeatedly attempt to build an image, it always assembles it without using any cached layer. I tried various options (`nocache=False`, `layers=True` etc.) but was unsuccessful.

My Dockerfile/Containerfile looks for example like this:

```Dockerfile
FROM docker.io/library/fedora:latest

RUN dnf update -y

RUN echo 'Hey'
```

Building the image using this library always re-executes all the steps:

```python3
import podman

client = podman.PodmanClient(base_url="unix:///tmp/podman.sock")

print(client.version())

image, logs = client.images.build(
dockerfile="Dockerfile",
tag="localhost/test-podman",
path="src/",
rm=False,
)
for log in logs:
print(log)
```

However if I use the [docker](https://pypi.org/project/docker/) library instead, it uses caches:

```python3
import docker

client = docker.DockerClient(base_url='unix:///tmp/podman.sock')

print(client.version())

image, logs = client.images.build(
dockerfile="Dockerfile",
tag="localhost/test-docker",
path="src/",
rm=False,
)

for log in logs:
print(log)
```

I'm experiencing this issue with podman version 5.2.2 (on Alma Linux 9), version 4.9.3 (Ubuntu 24.04 in WSL), version 5.4.1 (on mac OS).

```console
$ time python run-podman.py

real 0m11.543s
user 0m0.118s
sys 0m0.027s
$ time python run-podman.py

real 0m12.186s
user 0m0.109s
sys 0m0.033s
$ time python run-docker.py

real 0m12.512s
user 0m0.147s
sys 0m0.011s
$ time python run-docker.py

real 0m0.323s
user 0m0.132s
sys 0m0.000s
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.