Open FabianRechsteiner opened 1 month ago
I didn't know Docker secrets! I'm passing passwords usually via .env
files with appropriate file permission (chmod 600
). Example:
services:
bbox:
image: sourcepole/bbox-server-qgis:v0.6.1
environment:
- PGPASSWORD={{ DB_PASSWORD }}
.env:
DB_PASSWORD=changeme
Currently, I am still using .env
files to pass variables, including passwords. However, this is not optimal, as passwords are used unencrypted within the container and can also be output in log files. I use Portainer for monitoring and as an overview of my running containers, networks, and volumes. In doing so, Portainer can read the environment variables and display passwords in plaintext.
This should be avoided at all costs. Therefore, it is advisable to use Docker Secrets for sensitive data like passwords and tokens. These allow for a more secure handling of confidential information.
Docker Secrets are primarily intended for Docker Swarm, but with the correct configurations, they can also be utilized in docker-compose files without Docker Swarm. This way, one can benefit from this security measure even in a regular Compose setup.
Description: I would like to know if it’s possible to pass passwords as secrets in Docker Compose, similar to how the official PostgreSQL image supports Docker secrets.
For instance, PostgreSQL allows the use of
_FILE
appended to environment variables, enabling password retrieval from files stored as Docker secrets. Here’s an example from PostgreSQL:I’m attempting to implement a similar setup in my compose.yaml file for a BBOX service that connects to a PostGIS database, and I would like to manage sensitive information like the database password using secrets. Here is my current compose.yaml configuration:
Is this a valid way to handle passwords securely using Docker Compose secrets, or is there a better approach to achieving this? Any advice on best practices for securely managing credentials in this context would be appreciated.