Reputation: 10150
I have a Dockerfile, and when I run docker build
from the command line it reuses unchanged layers as expected. However, when I start the build using the Python API, it always rebuilds all steps. Any idea what the problem could be? My code looks like this:
import docker
with contextlib.closing(docker.from_env()) as client:
stream = client.api.build(path=workdir, tag=newtag, rm=True)
for part in stream:
# process stream
print(part)
Upvotes: 0
Views: 95
Reputation: 3275
docker
library does not currently support BuildKit, see this thread for more information.
BuildKit is "an improved backend to replace the legacy builder. BuildKit is the default builder for users on Docker Desktop, and Docker Engine as of version 23.0."
Because the build backend is different, docker cannot reuse the cache between the two different styles.
You can verify this by inspecting the final SHA for the images, they should differ.
The cache should populate though after you build it once with your python program. However, if you really want these to work together, you can disable the buildkit and use the legacy builder by doing this:
DOCKER_BUILDKIT=0 docker build .
Upvotes: 0