Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set Password for Postgres using docker-compose

Tags:

I am not able to set Password for Postgres using Docker-compose. Postgres is loading without password and with the default user name "postgres", non of the environment variables below seems to applied. below is the db service of my docker-compose.yml file: (version 3)

db:
  image: postgres
  container_name: postgres
  environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: db
  restart: unless-stopped
  volumes:
    - ./postgres-data:/var/lib/postgresql/data
  ports:
    - "5432:5432"

Note I tried using the "-POSTGRES_USER=" as well, it didn't work

Also, I deleted all old containers/volumes.

Any idea?

like image 876
Issam Avatar asked Aug 26 '17 03:08

Issam


People also ask

What is the default postgres password?

For most systems, the default Postgres user is postgres and a password is not required for authentication.

What is docker default password?

The password is 'ubuntu' for the 'ubuntu' user (at least in docker for ubuntu :14.04.


2 Answers

The problem should be with the volume attached. When your container start it will add the credentials you give him, but then the volume will be attached and that will cause this information being rewritten.

For more information have a look at https://github.com/docker-library/postgres/issues/203#issuecomment-255200501.

like image 147
ilmucio Avatar answered Oct 15 '22 02:10

ilmucio


The main reason being use of ':' instead of "=" in the environment section. Ideally it should look like this:

db:
  image: postgres
  container_name: postgres
  environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD= pass
      - POSTGRES_DB= db
  restart: unless-stopped
  volumes:
    - ./postgres-data:/var/lib/postgresql/data
  ports:
    - "5432:5432"

Although very late to this but I hope this helps someone who comes looking for a similar solution.

like image 36
sxddhxrthx Avatar answered Oct 15 '22 04:10

sxddhxrthx