Reusable containers
**Warning** breaking change. The labels used to track reusable containers have changed. Your containers may need to be removed manually when migrating to this release.
This release fleshes out "reusable containers" and applies the same logic to networks and volumes.
Image caching
Image building can be slow. For some images, its by far the slowest part of your test cycle. Optimising your image build for layer reuse can help. But after many iterations your machine will acrue many iterations of your image as well. To keep the benefits of layer reuse but also keep housekeeping simple we recommend tagging your images when using `build` fixtures. This means that when you run `docker image prune` old versions of your image are deleted and the current version is kept.
python
from pytest_docker_tools import build
my_image = build(
path='db',
tag='localhost/myproject:latest'
)
If you make 20 changes to your project that cause 20 builds you will now see 20 images in `docker images ls`. Only one will be tagged `localhost/myproject:latest`. And when you run `docker image prune` that one image will be kept and the other 19 will be removed.
There is a problem, though. Multi-stage builds. You can't tag your building stages, so running `docker image prune` will delete your builder stages. These are often the slowest parts of the multi-stage build, and now you have to rebuild them.
As of pytest-docker-tools 2.0.0 `build()` gains a `stages` property. It lets you tag your builders.
python
from pytest_docker_tools import build
my_image = build(
path='db',
tag='localhost/myproject:latest',
stages={
'builder': 'localhost/myproject:builder'
}
)
Now when you prune the latest versions of your build stages and your final target image are all preserved. And the old versions are thrown away. Better build speeds, and you don't need a bigger hard drive.