-
Notifications
You must be signed in to change notification settings - Fork 28
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
Reduce docker image size. #322
Comments
@demeringo have any of you thought about making a multi-stage build https://docs.docker.com/build/building/multi-stage/ ? Edit: it seems that it is the case https://github.com/Boavizta/boaviztapi/blob/main/Dockerfile#L21C1-L22C40 This is often a good way to reduce the image size, as well as building a lightweight os such as alpine ? Also, I see no .dockerignore file, is it expected ? I can take a look into it, I'm used to create light containers. |
I don't have much expertise on the subject, so I'll trust your expertise if you want to contribute. |
Adding a .dockerfile allows me to already gain 70 MB REPOSITORY TAG IMAGE ID CREATED SIZE
boavizta/boaviztapi 1.3.7 3f6ba5cfaf75 5 seconds ago 524MB
<none> <none> ef9616799172 5 hours ago 596MB I got issue with the hardcoding of the path of the pyproject.toml at the moment File "/usr/local/lib/python3.12/site-packages/boaviztapi/main.py", line 35, in <module>
version = toml.loads(open(os.path.join(os.path.dirname(__file__), 'pyproject.toml'), 'r').read())['tool']['poetry'][
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.12/site-packages/boaviztapi/pyproject.toml' but cracking the issue will allow me to gain again 64 MB REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> bab25d783b8a 2 minutes ago 460MB I will also propose a Dockerfile based on pythonVERSION-alpine, which has a lower base image size (cf https://hub.docker.com/_/python/tags?name=3.12): 17 MB for alpine vs 44 MB for slim. I know that some people don't like alpine, so it's better to keep a debian based image. |
I tried to build using alpine but I don't gain as much as I expected REPOSITORY TAG IMAGE ID CREATED SIZE
boavizta/boaviztapi 1.3.7 ffdd2633beb0 23 seconds ago 402MB
<none> <none> 61285d96bddc 11 minutes ago 460MB So I will stick with the current image used, unless you think that this is still interesting ? |
Problem
There may be room to optimize the size of the docker image (around 650 MB at the moment)
Solution
See if we can optimize the resulting image either by:
Alternatives
Additional context or elements
The text was updated successfully, but these errors were encountered: