How to cut size of python in Debian Java based Docker image?

mobile_developer42 :

I am trying to reduce the size of my Docker image, it has to have both python for aws-cli utilities and java for local testing using local-dynamodb. I have tried using alpine image with openjdk, but because it uses musl instead of glibc it does not work.

My image is currently 870 MB, most of it would the python3 package I install using apt-get. What can I do to cut down it's size? Is there any way to get 'slim' version like the ones that are preinstalled on alpine/debian?

Here's my Dockerfile:

FROM openjdk:8u222-jre-slim-buster

RUN apt-get update && apt-get -y install curl gnupg2 && \
    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | 
    tee /etc/apt/sources.list.d/yarn.list && \
    apt update && apt-get install -y \
      groff \
      jq \
      nodejs \
      less \
      yarn \
      python3-dev \
      python3-pip && \
      pip3 install --upgrade pip awscli boto3 aws-sam-cli 
YBadiss :

You can find slimmed versions docker python images on dockerhub https://hub.docker.com/_/python

However, I would advise to first get more info on what is taking up space in your image: Don't try to optimise what you haven't measured.

In this case, and from personal experience, I would think that the Java part is what's taking up space.

You can also cleanup apt-get after you're done, using something like

apt-get remove --purge ${builds_deps} -y
apt-get clean
rm -rf -- /var/lib/apt/lists/*

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324913&siteId=1