Docker Community Forums

Share and learn in the Docker community.

How do I know that Alpine is the base image for my container?

Hello,

I am new to this Docker technology/platform.
I have created 2 examples and for the first one Dockerfile looks something like this

FROM python:3.6

RUN mkdir src
ADD testclient.py /src/
RUN pip install pyzmq

And for the second one Dockerfile looks something like this

FROM alpine:3.7
RUN apk update

FROM python:3.6
RUN pip install pyzmq

RUN mkdir src
ADD testclient.py /src/

How will I validate that Alpine is the base image for container that is created out of the second example?

Many thanks in advance.

Regards,
Sakar

It will not be because python:3.6 is built on Debian Stretch. If you want it to be based on Alpine, why don’t you use python:3.6-alpine directly?

Thanks for the suggestion. I used the same in my next trial.
I have another issue to address now

FROM python:3.6-alpine

RUN apk --no-cache update
RUN apk --no-cache add build-base
RUN apk --no-cache add libzmq
RUN apk --no-cache add zeromq-dev

RUN pip3 install pyzmq

reduce image size by cleaning up the build packages

RUN apk del build-base zeromq-dev

RUN mkdir src
ADD test.py /src/

WORKDIR /src/

How do I reduce the image size to whatever least possible with above Dockerfile specifications?
Currently it is reporting about 196 MB…

Any suggestions?

Regards,
Sakar Kalkotwar

First you could combine the different RUN commands into one. Then you could combine the build dependencies into a virtual package

RUN apk --update add --virtual ...

and remove this after pip3 install, as described here.
But in general I wouldn’t worry too much about the size of a single image and instead to try to limit the overall size of the system. Images consist of several layers (from the docs: “Each instruction in a Dockerfile creates a layer in the image.”). If you build all the images in the same way many of these layers will be shared between them and don’t require additional space.