D
D
de-dup-i-dipi2019-08-25 02:12:47
PostgreSQL
de-dup-i-dipi, 2019-08-25 02:12:47

Docker, postgres and database creation?

When I run the image creation from the terminal with the command

docker run --name proj_bd -d \
    --env 'DB_NAME=main_base' \
    --env 'DB_USER=user' --env 'DB_PASS=pass' \
    --env 'DB_EXTENSION=pg_trgm' \
    postgresql:11.1

That creates a database and a role with a password. When I try to do via docker-compose up
version: "3.7"
services:
  postgresql:
    image: postgres:11.1
    env_file: vars.sh
    volumes:
      - ./dockerfiles/pgdata:/var/lib/postgresql/data/pgdata
    ports:
      - "5433:5432"

That role is not created, the database is not created, only the default postgres role. When you run docker-compose config, the parameters from the variable file get into the environment field. How to force to create a database with parameters via docker-compose?
Just in case, an example of what's in the variables
DB_NAME=main_base
DB_USER=user
DB_PASS=pass
DB_HOST=postgresql

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
display: block, 2019-08-25
@de-dup-i-dipi

The database and the user are created by running with the variables from the description https://hub.docker.com/_/postgres

version: '3.3'

services:
  pgsql:
    image: postgres:11.1
    ports:
      - 5432:5432
    volumes:
      - ./pgsql:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: app
      POSTGRES_USER: app
      POSTGRES_DB: app

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question