I’ve created a database initialization script that creates the database and adds an entry to a specific table.
insert into user (email) values (${USER_EMAIL})
My docker-compose file is similar to this one:
version: '3.7'
services:
postgres:
image: postgres:10.5
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
logging:
options:
max-size: 10m
max-file: "3"
ports:
- '5438:5432'
volumes:
- ./postgres-data:/var/lib/postgresql/data
# copy the sql script to create tables
- ./sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql
# copy the sql script to fill tables
- ./sql/fill_tables.sql:/docker-entrypoint-initdb.d/fill_tables.sql
USER_EMAIL is an env variable is is not being set in the script. What’s the right way to do this?
2
Answers
if you want to give a value for USER_EMAIL, you can simply add it in environment section.
in your script just set a value for USER_EMAIL.
The
USER_EMAIL
is not going to be available in sql file. I think you already tried that. Try usingenvsubst
. So something likeI haven’t tried pulling that pg image. So not sure if
envsubst
is available inside.