docker build -rm should be default #4291

Closed
cpuguy83 opened this Issue Feb 23, 2014 · 6 comments

Comments

Projects
None yet
4 participants
@cpuguy83
Contributor

cpuguy83 commented Feb 23, 2014

When doing docker build, -rm should be default.
How often do we need to inspect the intermediate containers when a build is successful? I'd wager absolutely never.
Meanwhile most people want to clear these pointless containers out as it just clutters up docker... and I assume doubles the space required (size of previmg + container dif + resulting img) for each step.

When a build fails, the intermediate containers are not removed anyway, so debugging is still possible regardless of -rm's value.

It would also be nice to have an easier way to clean up intermediate containers after debugging is complete.

cpuguy83 added a commit to cpuguy83/docker that referenced this issue Feb 23, 2014

fixes part of moby#4291
Docker-DCO-1.1-Signed-off-by: Brian Goff <cpuguy83@gmail.com> (github: cpuguy83)
@marcusramberg

This comment has been minimized.

Show comment
Hide comment
@marcusramberg

marcusramberg Feb 23, 2014

Contributor

👍

Contributor

marcusramberg commented Feb 23, 2014

👍

@ewindisch ewindisch closed this Feb 28, 2014

@ewindisch

This comment has been minimized.

Show comment
Hide comment
@ewindisch

ewindisch Feb 28, 2014

Contributor

This has been merged but for anyone running an older version of Docker finding this ticket, it might be useful to have the following command that will delete all intermediary images:

docker rmi $(comm -3 <(docker images -q | sort) <(docker images -q -a | sort)  | sed 's/\t//')
Contributor

ewindisch commented Feb 28, 2014

This has been merged but for anyone running an older version of Docker finding this ticket, it might be useful to have the following command that will delete all intermediary images:

docker rmi $(comm -3 <(docker images -q | sort) <(docker images -q -a | sort)  | sed 's/\t//')
@cpuguy83

This comment has been minimized.

Show comment
Hide comment
@cpuguy83

cpuguy83 Feb 28, 2014

Contributor

@ewindisch This is really needed for intermediate containers.

Contributor

cpuguy83 commented Feb 28, 2014

@ewindisch This is really needed for intermediate containers.

@ewindisch

This comment has been minimized.

Show comment
Hide comment
@ewindisch

ewindisch Feb 28, 2014

Contributor

@cpuguy83 I agree on the validity of the issue -- the pull request was merged ;-)

Contributor

ewindisch commented Feb 28, 2014

@cpuguy83 I agree on the validity of the issue -- the pull request was merged ;-)

@tianon

This comment has been minimized.

Show comment
Hide comment
@tianon

tianon Feb 28, 2014

Member

@ewindisch yes, but @cpuguy83 is pointing out that your one-liner deletes images, and docker build --rm has nothing to do with images. :)

Member

tianon commented Feb 28, 2014

@ewindisch yes, but @cpuguy83 is pointing out that your one-liner deletes images, and docker build --rm has nothing to do with images. :)

@ewindisch

This comment has been minimized.

Show comment
Hide comment
@ewindisch

ewindisch Feb 28, 2014

Contributor

@tianon @cpuguy83 oh, right. Well, then you probably want:

# Remove containers
for img in $(comm -3 <(docker images -q | sort) <(docker images -q -a | sort)  | sed 's/\t//'); do docker ps -a | grep $img | sed 's/\s\+.*//'; done | xargs docker rm
# Remove images
docker rmi $(comm -3 <(docker images -q | sort) <(docker images -q -a | sort)  | sed 's/\t//')
Contributor

ewindisch commented Feb 28, 2014

@tianon @cpuguy83 oh, right. Well, then you probably want:

# Remove containers
for img in $(comm -3 <(docker images -q | sort) <(docker images -q -a | sort)  | sed 's/\t//'); do docker ps -a | grep $img | sed 's/\s\+.*//'; done | xargs docker rm
# Remove images
docker rmi $(comm -3 <(docker images -q | sort) <(docker images -q -a | sort)  | sed 's/\t//')

@dat-boris dat-boris referenced this issue in circleci/circleci-docs Sep 26, 2016

Closed

Save intermediate layer to allow caching #342

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