Creating Containers - Best Practices
Best Practices for adding services to Docker
- Ensure the compose file for the entire service is located within compose/service.yml - this should then be referenced within the global docker-compose.yml
- Ensure ALL volumes are mapped inside of appdata, and seperated out when required.
- EG - if you have a service which has a storage volume for the frontend container, and the database container, seperate them out into appdata/SERVICE/app and appdata/SERVICE/db
- This should be referenced using the .env variable $DOCKERDIR. eg, $DOCKERDIR/appdata/SERVICE/app
- If using environment variables inside of Compose files, try and keep these hardcoded within the global .env file. Includes items like a database or username referenced for the container.
- If needing sensitive information like passwords or root credentials inside of compose files, ensure you utilise the SECRETS functionality in Docker.
- Sudo create a text file in secrets/, paste the information, and reference this within docker-compose.yml and the service.yml file
-
COMPOSE FILE
docker-compose.yml under SECRETS:ENVIRONMENTVARIABLE=/run/secrets/secret_name -
secret_name: file: $DOCKERDIR/secrets/secret_name
- Sudo create a text file in secrets/, paste the information, and reference this within docker-compose.yml and the service.yml file
- Where possible, reduce container permissions to specific UID and GID's. There are hardcoded variables you can use in .env called $PUID and $PGID in compose files.
- Some containers can support this in environment variables, others can be forced, some do not behave properly. Follow maintainers direction.
- Ensure containers are manually defined in Networks. This should be the socket_proxy network where possible.
- If needing to be exposed via Traefik, ensure that t3_proxy network is included as well
- If exposing interface via Traefik, consider if you need to expose ports manually within the compose file - sometimes it is not required given the Traefik labels do this as well
- Update documentation if adding a service or if something complex is being added for reference
- Consider reducing what you need to expose via a external interface. If an external interface is required, ensure you are using highly protected middlewares, preferably with authentication.
No comments to display
No comments to display