Since Docker 17.05 it has been possible to use multi stage builds to reduce the size of the final docker image, ref https://docs.docker.com/develop/develop-images/multistage-build/.
The Docker image for Oracle Database 18.3.0-se2, as built by this repository, is 18GB in size. A multi-stage build can reduce this to about half.
Actually, it can't. Multi-stage builds copy all binaries over as root and upon changing the ownership of these files the image will get bloated again.
What does help is the usage of the --squash option, which is still in experimental status since introduced but works just fine. If the image is built with --squash you save about 10GB of the image.
All of this is written up here: https://geraldonit.com/2017/11/13/how-to-create-small-docker-images/
I highly recommend turning on experimental and using --squash. You can just pass the flag on to ./buildDockerImage.sh -s -o --squash
Leaving this open for now until the PR got validated.
You can copy the files with predefined owner, so no chown is needed afterwards.
i.e :
COPY --from=build-stage /usr/ /usr
COPY --from=build-stage --chown=oracle:oinstall /home/oracle /home/oracle
COPY --from=build-stage --chown=oracle:oinstall /etc/oratab /etc/oratab
COPY --from=build-stage --chown=oracle:oinstall /opt/oracle /opt/oracle
This reduces the image size (for 12.2.0.1-se2 which I'm using now) to 6.3GB.
The --squash option is experimental and is up for discussion to be removed (although this has been going on since 2017 :) : https://github.com/moby/moby/issues/34565
[edit] Sorry, I see you already are implementing this. Worked great for me.
PR #979 got submitted.
And PR #979 got merged. @elygre, are you fine with closing this issue?
Most helpful comment
You can copy the files with predefined owner, so no chown is needed afterwards.
i.e :
COPY --from=build-stage /usr/ /usr
COPY --from=build-stage --chown=oracle:oinstall /home/oracle /home/oracle
COPY --from=build-stage --chown=oracle:oinstall /etc/oratab /etc/oratab
COPY --from=build-stage --chown=oracle:oinstall /opt/oracle /opt/oracle
This reduces the image size (for 12.2.0.1-se2 which I'm using now) to 6.3GB.
The --squash option is experimental and is up for discussion to be removed (although this has been going on since 2017 :) : https://github.com/moby/moby/issues/34565
[edit] Sorry, I see you already are implementing this. Worked great for me.