If I want to use different credentials on different servers, environment variables work great with docker compose.
As an example I will use docker-compose.yml file from Docker + Redis + Redis Commander article.
Source files can be found here: https://github.com/ikknd/docker-study in folder recipe-07
Notes:
If I now try this docker-compose.yml file without .env file, credentials to redis-commander will be admin/qwerty.
If I create .env file next to my yml file and put the following inside, credentials to redis-commander will be test/1234:
REDIS_USER=test
REDIS_PASSWORD=1234