Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Further reduce the size of the docker image #3972

Merged
merged 4 commits into from
Oct 1, 2018

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Sep 27, 2018

  • get rid of the pip wheel cache
  • get rid of /synapse (everything we need ends up in /usr/local/lib/python2.7/site-packages

* get rid of the pip wheel cache
* get rid of /synapse (everything we need ends up in
  /usr/local/lib/python2.7/site-packages
@richvdh
Copy link
Member Author

richvdh commented Sep 27, 2018

This is all very well, but we end up with an image which is built on top of a layer which adds /synapse, and then we remove /synapse in the final layer. Is there a way to avoid the redundant layer?

@richvdh richvdh requested a review from michaelkaye September 27, 2018 17:11
@michaelkaye
Copy link
Contributor

You can do it with the builder container pattern : https://docs.docker.com/develop/develop-images/multistage-build/

That way you build synapse then throw away the container(s) you built it in and just copy the required bits into a new container - it makes it a little easier than having that one multi-line RUN command to try to make a single image.

Copy link
Contributor

@michaelkaye michaelkaye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So - we can deploy this for a slight gain, if we remove the "rm -rf /synapse" as that's not doing anything useful to the size

Doing it properly will be about using the multi-stage builder to:

FROM python-alpine...
RUN apk install runtime_deps 
RUN apk install build_deps # seperate layers, because we can re-use the layer with just the runtime deps below, speeding up builds I think.

pip install to /target/ # somehow, how do you do that in python
other bits here

FROM python-alpine
RUN apk install runtime_deps # this is ok as a separate layer
COPY --from = 0 /target

Then i think we get to re-use layers where we want them - runtime dependencies, and build dependencies, without affecting the end image size.

setup.cfg \
setup.py \
synapse \
&& rm -rf /synapse \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove this line then this will reduce the size a little without doing deletes that aren't worthwhile.

This means we can get rid of a whole load of cruft which we don't need.
@richvdh
Copy link
Member Author

richvdh commented Sep 27, 2018

well, in for a penny, in for a pound. A semi-interesting exercise in learning how dockerfiles work.

@richvdh richvdh requested a review from michaelkaye September 27, 2018 23:14
docker/Dockerfile Outdated Show resolved Hide resolved
docker/Dockerfile Outdated Show resolved Hide resolved
docker/Dockerfile Show resolved Hide resolved
@richvdh richvdh merged commit 53c5fa4 into develop Oct 1, 2018
@richvdh richvdh deleted the rav/reduce_docker_image_more branch October 1, 2018 11:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants