Hi there,
I’m developing a container that contains a few of my favorite tools and I’ve been trying to follow a few guides on how to do multi-stage building to reduce the size of my image however the image is still about 1GB. I think the biggest culprit is AzureCLI. Any tips on how to further reduce the size?
FROM debian:12.6-slim AS builder
RUN apt-get update && apt-get install -y \
curl \
apt-transport-https \
lsb-release \
gnupg \
ca-certificates
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
RUN curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz && \
tar -zxvf openshift-client-linux.tar.gz && \
mv oc kubectl /usr/local/bin/ && \
rm -f openshift-client-linux.tar.gz
FROM debian:12.6-slim
COPY --from=builder /usr/bin/az /usr/bin/az
COPY --from=builder /usr/local/bin/oc /usr/local/bin/oc
COPY --from=builder /usr/local/bin/kubectl /usr/local/bin/kubectl
COPY --from=builder /opt/az /opt/az
CMD ["/bin/bash"]
If the azure cli works with alpine as well, you should consider switching your base image to alpine.
Furthermore, did you check what’s inside the oc-cli tar? It looks like kubectl is just a symlink to oc. If this is the case, you would end up having the same binary twice in the image. You could use a symlink instead of having the same binary included in the image.
Update: seems like there is no easy win with the recent Alpine 3.20.3 version: it comes with python 3.11, and the azure-cli install script is not compatible with > 3.10.
At least the symlink reduces the image by ~100Mb. To my surprise, the oc binary seem to switch to vanilla kubectl behavior if it’s called using the symlink kubectl.
Yeap, I came to the same conclusion as you did with the python version. I did try to solve it but it became a bit yanky and it’s just a tool container - shouldn’t be yanky at all.
I didn’t know that about the oc binary, nice catch! That’s at least some reduction.