###### tags: `Study Circle Note`, `Docker in Action 2ed` # Docker in Action 2ed 第七次 2021-09-04 - Chapter 7. Packaging software in images ## 討論 - Q: 先用 golang 的 image 去compile 成執行檔,再把執行檔包到別的 image。如果現在換台機器(不同cpu架構), 那會有影響嘛?還是在docker 裡面就都沒差 - A: 基本上是同個 OS 與 CPU arch 就行 - [buildx](https://docs.docker.com/buildx/working-with-buildx/) ## 補充 ### Best practice <iframe width="560" height="315" src="https://www.youtube.com/embed/JofsaZ3H1qM" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> - https://docs.docker.com/develop/develop-images/dockerfile_best-practices/ - https://www.slideshare.net/Docker/dcsf19-dockerfile-best-practices * 節錄:前面 p6~33 都是多數大家知道的 best practices * 最常改動的放到最後 * 盡量避免 `COPY .` * `apt-get update && install` 寫在同一行 * 移除不必要 dependencies 及 package manager cache * 盡可能的使用官方 image * 不要用 latest tag - 後面 multi-stage 滿值得一看的,titile: not just for reducing image * 利用 `docker build --stage_nmae` * 利用 globle var( ARG ) 定義不同 image name, ex: `docker build --target release --build-arg flavor=jessie` * 定義不同 env stage(dev, release, test, lint...) * build concurrently: 套用多個 `COPY --from ...` ### Docker lint * https://github.com/hadolint/hadolint