Best practices for container image creation
In this section, we are going to recommend a list of the best practices you can follow to create your applications, thus improving your applications’ security, reusability, and building processes:
- Only include the files that are strictly necessary for your application. Don’t install packages, binaries, libraries, and any file your application doesn’t need, and keep image content as small as possible, exposing a minimal attack surface.
- Use the
.dockerignore
file to avoid passing unnecessary files from your build context to container runtimes. - Prepare debugging versions of your images, including some binaries or tools that may help you resolve an issue, but never use these images in production.
- Prepare the logic of your Dockerfiles to accommodate your changes; hence, include your code close to the end of the file, and think about how many modules or dependencies may need to be changed to execute the...