Unable to set file secrets passwords on docker-compose

Viewed 574

I want to access a secret file with docker-compose. I follow many tutorials and reproduce the structure. The container is launched but when I need to log in, the right string to enter is "/run/secrets/sec_pgadmin_default_email". I want the login to be the one inside my secret file: admin. In this secret file pgadmin_default_email.txt, there is only the word admin. I don't know if the structure of this file is good. Should it be a dictionary or something else ?

version: '3.8' services:   pgadmin4:    
    build:
      context: ./dockerfiles/
      dockerfile: dockerfile_pgadmin4 
    image: img_pgadmin
    container_name: cont_pgadmin4
    ports:
      - "80:80" 
    secrets:
      - sec_pgadmin_default_email 
      - sec_pgadmin_default_password
    environment:
      - PGADMIN_LISTEN_PORT=80
      - PGADMIN_DEFAULT_EMAIL=/run/secrets/sec_pgadmin_default_email
      - PGADMIN_DEFAULT_PASSWORD=/run/secrets/sec_pgadmin_default_password

secrets:   
  sec_pgadmin_default_email:
    file: ./.secrets/pgadmin_default_email.txt   
  sec_pgadmin_default_password:
    file: ./.secrets/pgadmin_default_password.txt

PS I just use the command docker-compose up -d, without swarn things or else. I don't define external secrets and I prefer not. Is it possible ?

1 Answers

the environment variable will be set to the path of the file containing the actual value. Not the actual value itself.

For example, in Go you could do something like:

var pgAdminDefaultEmailFile = os.Getenv("PGADMIN_DEFAULT_EMAIL") // get the file
pgAdminDefaultEmailValue, err := ioutil.ReadFile(pgAdminDefaultEmailFile) // get the value

if err != nil {
    log.Fatal(err)
}
pgAdminDefaultEmail = string(pgAdminDefaultEmailValue) // parse out the value
Related