[Docker] Best practices
8 of the best practices that we should be following are:
- Using official images from docker
- Using a fixed version and not the latest from the images
- Don’t use a full-blown OS in Docker images (Try to use Alpine to save some space)
- Optimize caching image layers (Restructure Dockerfile to have the commands from least changing to most frequently changing commands)
- Use .dockerignore file to save space and lower the image’s size
- Make use of multistage builds (Separate build from runtime stage)
- Don’t use root as a user in the container (Create a dedicated user and group in the Dockerfile)
- Scan Images for vulnerabilities (Integrate docker container scanning in CI/CD)