Skip to content

Refactor Dockerfile with best practices #691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

PeterDaveHello
Copy link
Contributor

Multiple best practices applied as below:

  • Replace deprecated MAINTAINER with LABEL maintainer
  • Remove additional apt clean as it'll be done automatically
  • Use apt-get instead of apt in script, apt does not have a stable CLI interface, and it's for end-user.
  • Put apt-get install & apt lists clean up in the same command
  • Use --no-install-recommends with apt-get install to avoid install additional packages
  • Use --no-cache-dir with pip install to prevent temporary cache
  • Use COPY instead of ADD for files and folders
  • Use spaces instead of mixing spaces with tabs to indent

Size change by the refactor, almost 100MB saved:

REPOSITORY   TAG      IMAGE ID       CREATED         SIZE
maigret      after    9e70c65dde32   1 minutes ago   543MB
maigret      before   a683f2b71751   7 minutes ago   635MB

Multiple best practices applied as below:

- Replace deprecated `MAINTAINER` with `LABEL maintainer`
- Remove additional `apt clean` as it'll be done automatically
- Use `apt-get` instead of `apt` in script, apt does not have a stable
  CLI interface, and it's for end-user.
- Put `apt-get install` & apt lists clean up in the same command
- Use `--no-install-recommends` with `apt-get install` to avoid install
  additional packages
- Use `--no-cache-dir` with `pip install` to prevent temporary cache
- Use `COPY` instead of `ADD` for files and folders
- Use spaces instead of mixing spaces with tabs to indent

Size change by the refactor, almost 100MB saved:

```
REPOSITORY   TAG      IMAGE ID       CREATED         SIZE
maigret      after    9e70c65dde32   1 minutes ago   543MB
maigret      before   a683f2b71751   7 minutes ago   635MB
```
@soxoj
Copy link
Owner

soxoj commented Oct 4, 2022

Wow, wonderful, thanks!
I'll merge it, but check manually fresh build image from dockerhub after ~10 min since merge, please 🙏

@soxoj soxoj merged commit 0a628d2 into soxoj:main Oct 4, 2022
@PeterDaveHello PeterDaveHello deleted the RefactorDockerfile branch October 4, 2022 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants