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

Reduce docker image size. #322

Open
demeringo opened this issue Sep 27, 2024 · 4 comments
Open

Reduce docker image size. #322

demeringo opened this issue Sep 27, 2024 · 4 comments
Labels
ci Related to continuous integration workflows enhancement New feature or request help wanted Extra attention is needed

Comments

@demeringo
Copy link
Collaborator

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:

  • using a lighter base image
  • double checking waht we embark in the resulting image

Alternatives

Additional context or elements

@demeringo demeringo added enhancement New feature or request help wanted Extra attention is needed ci Related to continuous integration workflows labels Sep 27, 2024
@jonperron
Copy link
Contributor

jonperron commented Dec 18, 2024

@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.

@da-ekchajzer
Copy link
Collaborator

I don't have much expertise on the subject, so I'll trust your expertise if you want to contribute.

@jonperron
Copy link
Contributor

jonperron commented Dec 20, 2024

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.

@jonperron
Copy link
Contributor

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci Related to continuous integration workflows enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants