Use-Case Project: Apply Docker Container Best Practices
Situation
You got a sample JavaScript application, it's a simple todo list manager that is running in Node.js, however, no real JavaScript experience is needed. We will just run it.
Task
- Create a
Dockerfile
to containerize project. - Apply Docker container best practices to work effectively with top ✅️ Dos & 🚫 Don'ts.
- Create a CI pipeline to automate the best practices checks.
Requirements
Ensure the following best practices are applied.
-
Essential Practices
- Use Dockerfile linter
- Check Docker language specific best practices
- Create a single application per Docker image
- Create configurable ephemeral containers
-
Image Practices
- Use optimal base image
- Pin versions everywhere
- Create image with the optimal size
- Use multi-stage whenever possible
- Avoid any unnecessary files
-
Security Practices
- Always use trusted images
- Never use untrusted resources
- Never store sensitive data in the image
- Use a non-root user
- Scan image vulnerabilities
-
Misc Practices
- Leverage Docker build cache
- Avoid system cache
- Create a unified image across envs
- Use ENTRYPOINT with CMD
Extras
Build:
docker build . -t docker-sample-app:v1
Run:
docker run -p 3000:3000 docker-sample-app:v1
View:
http://localhost:3000
Resources
- Containers - Docker Fundamentals
- Containers - Docker Best Practices
- Continuous Integration - GitHub Actions Essentials
- Continuous Integration - Pipelines and Quality Gates
Reference
tip
Once you are done, compare your solution with the reference.
Ensure that you understand all aspects of the reference.