𝗗𝗲𝗽𝗹𝗼𝘆 𝗟𝗮𝗿𝗮𝘃𝗲𝗹 𝗪𝗶𝘁𝗵 𝗗𝗼𝗰𝗸𝗲𝗿 𝗔𝗻𝗱 𝗞𝘂𝗯𝗲𝗿𝗻𝗲𝘁𝗲𝘀
Your Docker images should be small. Large images slow down your deployment.
Use multi-stage builds to fix this.
Stage one is the builder.
- Install system tools.
- Install Composer and NPM.
- Compile your assets.
- This stage does not go to production.
Stage two is production.
- Use a light Alpine image.
- Copy only the needed files from the builder.
- Remove build tools.
- This keeps the image lean.
You need three more things for a professional setup:
- Nginx configuration.
- Log to stdout and stderr.
- Block access to your SQLite database.
- Send PHP requests to port 9000.
- PHP optimization.
- Turn on OPcache.
- Hide your PHP version for security.
- Set memory limits for large tasks.
- Supervisord.
- Run Nginx and PHP-FPM together.
- Ensure both start and restart automatically.
This setup works well for Kubernetes. It is fast and secure.