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

Split Dockerfile in two stages: builder and runtime. #31

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

pablospe
Copy link
Contributor

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

…he 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:
```bash
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:
```bash
docker build -t pyceres:latest .
```
is equivalent to specifying `--target runtime`, as runtime is the final stage in
the Dockerfile.
@pablospe pablospe marked this pull request as draft January 28, 2024 20:38
@pablospe pablospe marked this pull request as ready for review January 28, 2024 21:57
@sarlinpe
Copy link
Member

sarlinpe commented Feb 6, 2024

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

@pablospe
Copy link
Contributor Author

pablospe commented Feb 6, 2024

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
Copy link
Contributor Author

pablospe commented Feb 6, 2024

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

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

Successfully merging this pull request may close these issues.

2 participants