Improve Dockerfile #56

Closed
opened 2025-12-28 23:22:44 +01:00 by adam · 2 comments
Owner

Originally created by @jlxip on GitHub (Jul 8, 2020).

The Dockerfile could definitely have some improvements that would make the final image a lot smaller.

  1. Does it really need to use archlinux as the base image (which is 415MB)? Should check if ubuntu (74MB) or alpine (5.6MB) do the trick. If archlinux is actually necessary because of some needed newer features, then no problem there.
  2. Each RUN command in the Dockerfile adds a new layer, so it doubles the size of the final image. Most Dockerfiles are doable in one or two RUN commands. Either that or use multi-stage Docker builds (more info here).
  3. Similar to above, WORKDIR could be perfectly avoided by just using cd.
  4. This is not necessary. New files should be outside the Dockerfile, and copied at the beginning via COPY, which would make changing them a lot easier and avoid working with the line terminator \ as much as possible, which is always a good thing.
  5. The commands executed in RUN, once it gets down to one or two of that instruction, should be in a separate shell script which would benefit from the maintainability perks of the previous point.
  6. Pacman cache should also be cleaned after installing the required packages.
Originally created by @jlxip on GitHub (Jul 8, 2020). The Dockerfile could definitely have some improvements that would make the final image a lot smaller. 1. Does it really need to use `archlinux` as the base image (which is 415MB)? Should check if `ubuntu` (74MB) or `alpine` (5.6MB) do the trick. If `archlinux` is actually necessary because of some needed newer features, then no problem there. 2. Each `RUN` command in the Dockerfile adds a new layer, so it doubles the size of the final image. Most Dockerfiles are doable in one or two `RUN` commands. Either that or use multi-stage Docker builds (more info [here](https://learnk8s.io/blog/smaller-docker-images)). 3. Similar to above, `WORKDIR` could be perfectly avoided by just using `cd`. 4. [This](https://github.com/sickcodes/Docker-OSX/blob/a6c9714a1d39820271fe39fabc30355c7aa4d55d/Dockerfile#L143) is not necessary. New files should be outside the Dockerfile, and copied at the beginning via `COPY`, which would make changing them a lot easier and avoid working with the line terminator `\` as much as possible, which is always a good thing. 5. The commands executed in `RUN`, once it gets down to one or two of that instruction, should be in a separate shell script which would benefit from the maintainability perks of the previous point. 6. Pacman cache should also be cleaned after installing the required packages.
adam closed this issue 2025-12-28 23:22:44 +01:00
Author
Owner

@sickcodes commented on GitHub (Jul 8, 2020):

  1. You can rewrite it in Alpine if you’d like. It’s for people so they can change the Dockerfile. Someone mentioned earlier a problem with Alpine. Arch is well known, good support, other Arch users can easily add PR’s.

  2. Not sure about that. I will look into it. The biggest part of the image is the .img.

  3. Docker documentation recommends WORKDIR over cd, if that recommendation has changed let me know.

  4. I like dockerfiles that have everything in the one file. You can paste it anywhere. Store it in an email, in a photo, in a note, print it out.

  5. I would say that 1 single file is more maintainable than a series of shell scripts. I am big believer of KIS.

  6. Good idea. Want to submit a PR?

@sickcodes commented on GitHub (Jul 8, 2020): 1. You can rewrite it in Alpine if you’d like. It’s for people so they can change the Dockerfile. Someone mentioned earlier a problem with Alpine. Arch is well known, good support, other Arch users can easily add PR’s. 2. Not sure about that. I will look into it. The biggest part of the image is the .img. 3. Docker documentation recommends WORKDIR over cd, if that recommendation has changed let me know. 4. I like dockerfiles that have everything in the one file. You can paste it anywhere. Store it in an email, in a photo, in a note, print it out. 5. I would say that 1 single file is more maintainable than a series of shell scripts. I am big believer of KIS. 6. Good idea. Want to submit a PR?
Author
Owner

@sickcodes commented on GitHub (Mar 10, 2021):

  1. We are now using archlinux:base-devel
  2. Most of the appropriate commands have been joined into single layers
  3. Now only using WORKDIR when necessary
  4. 100% external files only. The Dockerfile will continue to be self-contained and any external files will be downloaded from this repo as appropriate, such as the current glibc patch, which is to be removed as soon as hub.docker.com updates their side, see https://github.com/sickcodes/Docker-OSX/pull/159
  5. Largest shell script moved to separate repo https://github.com/sickcodes/osx-serial-generator
  6. Pacman cache is cleaned after every run now!

Closing as seem to have covered most of these points by now, thank you!

@sickcodes commented on GitHub (Mar 10, 2021): 1. We are now using archlinux:base-devel 2. Most of the appropriate commands have been joined into single layers 3. Now only using `WORKDIR` when necessary 4. 100% external files only. The Dockerfile will continue to be self-contained and any external files will be downloaded from this repo as appropriate, such as the current glibc patch, which is to be removed as soon as hub.docker.com updates their side, see https://github.com/sickcodes/Docker-OSX/pull/159 5. Largest shell script moved to separate repo https://github.com/sickcodes/osx-serial-generator 6. Pacman cache is cleaned after every run now! Closing as seem to have covered most of these points by now, thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Docker-OSX#56