> For the complete documentation index, see [llms.txt](https://til.duyet.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.duyet.net/data-engineering/docker/optimize-the-docker-image-size.md).

# Optimize the Docker Image Size

## Cleaning up in the same layer

```
FROM ubuntu:14.04
RUN apt-get update && \
    apt-get install -y curl python-pip && \
    pip install requests && \
    apt-get remove -y python-pip curl && \
    rm -rf /var/lib/apt/lists/*
ADD ./my_service.py /my_service.py
ENTRYPOINT ["python", "/my_service.py"]
```

## Apt install with \`--no-install-recommends\`&#x20;

```
...
RUN apt-get install -y --no-install-recommends curl python-pip
...
```

## Multi-Stage Builds

```
FROM golang:1.8-alpine as builder
RUN go get github.com/kardianos/govendor
RUN go get github.com/nicksnyder/go-i18n/goi18n
RUN go get github.com/jteeuwen/go-bindata/go-bindata
RUN make build # Exports binaries to to ./bin/$BINARY

FROM alpine
COPY --from=builder ./bin/replicated /bin/replicated
ENTRYPOINT ["/bin/replicated"]
```

## Using distroless base images

{% content-ref url="/pages/-M\_ZyRdTW3dCU0GSzn-P" %}
["Distroless" Docker Images](/data-engineering/docker/distroless-docker-images.md)
{% endcontent-ref %}

## Dive - **A tool for exploring a docker image**

{% embed url="<https://github.com/wagoodman/dive>" %}

![](/files/-M_ZzBeuAP5u7AczVlOQ)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.duyet.net/data-engineering/docker/optimize-the-docker-image-size.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
