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

multistage images.build() leaves unwanted images even if rm and forcerm is True (docker=6.1.3) #3163

Closed
arsolics opened this issue Jul 22, 2023 · 3 comments

Comments

@arsolics
Copy link

echo "####" ; date ;  echo "####" ; docker images ;  echo "####" ; python testing.py ;  echo "####" ;docker images ;echo "####" ; date ;echo "####" ; cat testing.py ; echo "####" ; cat testing/Dockerfile 
####
Sat Jul 22 19:24:10 UTC 2023
####
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
####
####
REPOSITORY   TAG       IMAGE ID       CREATED                  SIZE
testing      latest    8ec1b7e719e6   Less than a second ago   77.8MB
<none>       <none>    8eee60b2d52b   2 seconds ago            77.8MB
ubuntu       22.04     5a81c4b8502e   3 weeks ago              77.8MB
####
Sat Jul 22 19:24:17 UTC 2023
####
#! /usr/bin/env python3


import docker
import string

client = docker.from_env()
labels = { "testing" : "true" }

image,log = client.images.build(
    path = "testing",
    dockerfile = "Dockerfile",
    labels = labels,
    pull = True,
    tag = "testing:latest",
    rm = True,
    forcerm = True,
    nocache = True
)

####
FROM ubuntu:22.04 as BUILD
RUN touch /tmp/build_phase

FROM ubuntu:22.04 as FINAL
COPY --from=BUILD /tmp/build_phase /tmp/final_phase
@naufalafif
Copy link

This is expected behavior from docker itself (not docker-py)
and created image is there as cached for next build.

see moby/moby#34151 (comment)

you can prune it if you want

@milas
Copy link
Contributor

milas commented Nov 21, 2023

Closing as this is expected behavior with multistage images as mentioned above

@milas milas closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2023
@thaJeztah
Copy link
Member

The --force-rm flag is also to remove containers used during build (that option only affects the classic builder); it does not affect removal of images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants