<p>I've created a simple Python service that connects with RabitMQ and Mattermost.
As I'm trying to build a Docker image, I noticed the image is far to big (916MB)</p>
<p>I created the image first without .dockerignore file. Deleted the image afterwards and created the image again by the command <code>docker image build --no-cache --pull -t &quot;gitlab-service&quot; .</code> but the size is still the same.</p>
<p>I uploaded the whole gitlab-service project on <a href="https://github.com/lucasscheepers/gitlab-service" rel="nofollow noreferrer">https://github.com/lucasscheepers/gitlab-service</a></p>
<p>Am I doing something wrong in the Dockerfile I created?</p>

Lucas Scheepers
<p>You are using a really big base image, so it's normal that you have that size.</p>
<p>If you are using the <code>python:3.8</code> image because you need some packages in order to compile your dependencies, then you can just get advantage of a multi-stage build and compile/download the dependencies with <code>python:3.8</code> but serve your application with <code>python:3.8-slim</code> that is way lighter:</p>
<pre><code>FROM python:3.8 as build

WORKDIR /usr/app
RUN python -m venv /usr/app/venv
ENV PATH=&quot;/usr/app/venv/bin:$PATH&quot;

COPY requirements.txt .
RUN pip install -r requirements.txt &amp;&amp; rm requirements.txt

FROM python:3.8-slim
RUN groupadd -g 999 python &amp;&amp; \
    useradd -r -u 999 python -g python
RUN mkdir /usr/app &amp;&amp; chown python:python /usr/app
WORKDIR /usr/app

COPY --chown=python:python --from=build /usr/app/venv ./venv
COPY --chown=python:python . .

USER 999

ENV PATH=&quot;/usr/app/venv/bin:$PATH&quot;

EXPOSE 8088
ENTRYPOINT [ &quot;python&quot;, &quot;main.py&quot;]
</code></pre>
<p>I built both from your GitHub project:</p>
<pre><code>❯ docker images | grep gitlab-service
gitlab-service        after        f2c1d1fab6fd   4 seconds ago   140MB
gitlab-service        before       b3e87980bccb   6 minutes ago   916MB
</code></pre>
