Problem with Docker image size

Hi,
So according to all guides to keep docker image sizes small you should keep your RUN statements to a minimum.
I tried with two different ways writing my Dockerfile

ubuntu@ip-172-31-31-165:~/iox/xxx$ cat Dockerfile 
FROM devhub-docker.cisco.com/iox-docker/base-x86_64:latest

RUN opkg update 
RUN opkg install iox-toolchain packagegroup-cisco-core-python python-dev python-pip git cmake
RUN python -m pip install -U pip
RUN pip install -U pip setuptools
RUN pip install 'requests[security]'
RUN pip install freeopcua
RUN pip install lxml

RUN mkdir /usr/bin/xxx
COPY Source /usr/bin/xxx
RUN chmod -R 777 /usr/bin/xxx/

CMD /opt/app/loop.sh

and

FROM devhub-docker.cisco.com/iox-docker/base-x86_64:latest

RUN opkg update && opkg install iox-toolchain packagegroup-cisco-core-python python-dev python-pip git cmake && \
  python -m pip install -U pip && \
  pip install -U pip setuptools && \
  pip install 'requests[security]' && \
  pip install freeopcua && \
  pip install lxml

RUN mkdir /usr/bin/xxx
COPY Source /usr/bin/xxx
RUN chmod -R 777 /usr/bin/xxx/
CMD /opt/app/loop.sh

Both images end up with the same size:

ubuntu@ip-172-31-31-165:~/iox/xxx$ sudo docker images
REPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZE
2xxx-python                                  2.0                 15cf9e504ed9        27 seconds ago      342 MB
2xxx-python                                  1.0                 fd77fb82e011        22 minutes ago      342 MB

Is this expected behavior?

Thanks
Oscar Bengtson

yes.
but you could delete git, cmake,python-pip and ‘python-dev’ after using them. (i’m assuming, that your app does not rely on them)
Then you could free some MB.

There is also a --squash option for docker build with the latest docker. This will squash your layers into a single one.