I want to make a postgres database image but don't want to expose password and username which are stored as environment variable when produced using docker-compose.yml file. Basically, I don't want anyone to exec into the container and find out the variables.
One way is to use docker-secrets, but I don't want to to use docker swarm because my containers would be running on a single host.
my docker-compose file -
version: "3"
services:
db:
image: postgres:10.0-alpine
environment:
POSTGRES_USER: 'user'
POSTGRES_PASSWORD: 'pass'
POSTGRES_DB: 'db'
Things I have tried -
1) unset the environment variable at the end of entrypoint-entrypoint.sh
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
unset POSTGRES_USER
nothing happened though. :(
2) init.sql inside docker-entrypoint-initdb.d, to create db, user and pass without using env. I shared the volume, as -
```
volumes:
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
```
and, on my host, inside docker-entrypoint-initdb.d, I saved an init.sql as -
CREATE DATABASE docker_db;CREATE USER docker_user with encrypted password 'pass';GRANT ALL PRIVILEGES ON DATABASE docker_db TO docker_user;
I moved inside the running container and this file was there but, no user or database was created as mentioned in the file.
I have been stuck on this for past two days, any help is much appreciated.