I'm trying to figure out the best practices for setting up installations in Docker. I know that the general guideline is to keep your Dockerfile efficient by minimizing the number of layers you create, as there's a limit of 127 layers. However, I'm also considering whether to include more complex operations in a separate bash script once the Dockerfile has done its initial work, especially when needing to install packages that aren't available through apt-get or when I have to add GPG keys and custom source lists.
For instance, I often have to create directories, clone repositories, and manage certificates—all of which might be cumbersome if placed in the Dockerfile, especially since they could lead to outdated images. The downside is that overloading a bash script can delay container startup times.
So, I'm looking for advice on what should ideally go in the Dockerfile versus what would be better suited for a bash script that runs at container startup. For example, if I want to install the Bitwarden Secrets CLI, should I embed that in the Dockerfile to have a fixed version or run it from a script to always get the latest version?
2 Answers
Typically, you'd want to pre-build your container with all necessary binaries and packages for optimal performance, since those will become part of your image. When new versions are released, that's where CI/CD pipelines can automate rebuilding to keep your image updated. However, for quick tests or instances where you need specific client versions, like different database clients, using a lightweight base image and adding clients via entrypoint scripts can work well. It keeps things flexible without requiring constant image updates.
You could also consider chaining commands in your Dockerfile using `&&`. Plus, multi-stage builds can help manage complexity by keeping the final image slim while allowing you to install whatever you need in separate build layers.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String