Is there a way to have a base docker image, and bu...
# general
a
Is there a way to have a base docker image, and build other docker images from that base? So, build a base python image with certain installations, then having the other docker images reference that image in the FROM command?
I noticed that this is something that can be done in other systems, like please: https://please.build/codelabs/k8s/#3. I would like to leverage something similar to avoid having to have each docker file repeat a bunch of things, and to also more strictly define the versions available for use.
h
You could achieve this with a macro where you specify the docker instructions in the target instead of a file.
r
You can have multiple
docker_image
target with dependency. You can see the last example in this tutorial https://blog.pantsbuild.org/optimizing-python-docker-deploys-using-pants/
c
still on my todo to add this to the documentation, but you can also have pants replace a target address in your FROM instruction. Example:
Copy code
docker_image(name="base", ...)  # this is src/images:base in this example 

docker_image(
  name="service",
  instructions=[
    "ARG BASE=src/images:base", 
    "FROM $BASE",
    ...
  ],
  ...
)
Only real world example I have right now is from the tests: https://github.com/pantsbuild/pants/blob/690e6a60ba244cc46dd191885ea7fa54a3e4554d/[…]src/python/pants/backend/docker/util_rules/dependencies_test.py