theia-ide / theia-apps

Theia applications examples - docker images, desktop apps, packagings
Apache License 2.0
1.04k stars 346 forks source link

optimizing docker image size #389

Closed snowch closed 4 years ago

snowch commented 4 years ago

The apt commands here have a cleanup operation: https://github.com/theia-ide/theia-apps/blob/master/theia-full-docker/Dockerfile#L292-L297

  apt-get clean && \
  apt-get autoremove -y && \
  rm -rf /var/cache/apt/* && \
  rm -rf /var/lib/apt/lists/* && \
  rm -rf /tmp/*

However, there are quite a few separate RUN ... apt-get update ... commands. Should a clean up be done after each of them to reduce the size of the layer committed by RUN?

marcdumais-work commented 4 years ago

Hi @snowch ,

According to my understanding of how Docker works, we indeed should do such a cleanup every time, since it needs to be done in the same RUN command, else the files stay in the image, hidden.

However we've experimented a couple of times with these cleanups, and could not see any impact on the final image size. Here one of them, where they were added everywhere in our theia-full image:

https://github.com/theia-ide/theia-apps/pull/372#pullrequestreview-432605505

As best as I can tell, maybe there is some Docker magic at play, maybe an optimisation specific for apt? Not sure.

You are welcome to improve image size by adding such cleanups in a PR, so long as there is a demonstrable size improvement.

snowch commented 4 years ago

I've switched to the python ide for the moment. Let's close this for now and reopen if I get a chance to look at the full images.

Many thanks!