Skip to content

Instantly share code, notes, and snippets.

@gmoon
Last active February 13, 2024 13:32
Show Gist options
  • Save gmoon/3800dd80498d242c4c6137860fe410fd to your computer and use it in GitHub Desktop.
Save gmoon/3800dd80498d242c4c6137860fe410fd to your computer and use it in GitHub Desktop.
Dockerfile for aws-cli, aws-sam-cli, and python3 on alpine linux
FROM alpine:3.10
RUN apk -v --no-cache --update add \
musl-dev \
gcc \
python3 \
python3-dev
RUN python3 -m ensurepip --upgrade \
&& pip3 install --upgrade pip
RUN pip3 install --upgrade awscli aws-sam-cli
RUN pip3 uninstall --yes pip \
&& apk del python3-dev gcc musl-dev
@jleivo
Copy link

jleivo commented Mar 30, 2023

Thanks for the commands, saved me a lot of time. In return, here is a small optimization suggestion:

The line 10 & 11 doesn't actually help the size of the image as the previous layers still keep the packages. To gain slimming benefits all of it needs to be in one line, like this:

RUN apk --quiet --no-cache --no-progress --update add
musl-dev gcc python3 python3-dev libffi-dev bash
&& python3 -m ensurepip --upgrade
&& pip3 install --upgrade pip awscli aws-sam-cli
&& apk del python3-dev gcc musl-dev libffi-dev

The difference is about 160 megabytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment