pyceres icon indicating copy to clipboard operation
pyceres copied to clipboard

Split Dockerfile in two stages: builder and runtime.

Open pablospe opened this issue 1 year ago • 3 comments

By dividing the Dockerfile into two stages, we significantly reduce the size of the final image. This is because the build dependencies, which are not required in the final image, are excluded.

You can create tags for each stage separately using the --target option:

docker build --target builder -t pyceres:builder .
docker build --target runtime -t pyceres:runtime .

However, if you run the docker build command without the --target option, it will build up to the last stage defined in the Dockerfile. So, running:

docker build -t pyceres:latest .

is equivalent to specifying --target runtime, as runtime is the final stage in the Dockerfile.

Reduction in size:

pyceres:runtime    2.48GB
pyceres:builder    8.98GB

pablospe avatar Jan 28 '24 20:01 pablospe

I've removed the dependency on COLMAP - is the Docker size still an issue?

sarlinpe avatar Feb 06 '24 13:02 sarlinpe

If I do docker images after building it: pyceres latest 7653326fc398 6 minutes ago 8.32GB

Which seems weird because it has a lot less dependencies.

I guess you don't need the cuda image anymore: FROM nvidia/cuda:${NVIDIA_CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} as builder Just changing to regular ubuntu image base could reduce the size.

I would still recommend doing the builder/runtime split, since it is not really needed all the *-dev libraries to run it.

pablospe avatar Feb 06 '24 21:02 pablospe

I quickly updated this PR locally, using regular ubuntu image and I get:

pyceres                                      runtime           93e79e43bd1a   55 seconds ago   425MB
pyceres                                      builder           2574cc974212   58 seconds ago   1.41GB

edit: I added some runtime libraries

pablospe avatar Feb 06 '24 21:02 pablospe