I am trying to create custom image from postgres:11.5-alpine so i made this dockerfile:
FROM postgres:11.5-alpine
LABEL MAINTAINER groot
ENV LANG en_US.utf8
ENV DBNAME pglocations
ENV USERNAME postgres
COPY init.sql /docker-entrypoint-initdb.d/
This is init.sql file:
/*--psql -U posgtres -p 5432
psql -U <username> -d <dbname> -1 -f <filename>.sql*/
psql -U posgtres -p 5432
CREATE DATABASE pglocations
WITH OWNER = postgres
ENCODING = 'UTF8'
LC_COLLATE = 'English_United States.1252'
TABLESPACE = pg_default
CONNECTION LIMIT = -1
TEMPLATE template0;
/*psql -U posgtres -d pglocations -1 -f pglocations.sql*/
I make image by this command:
docker build -t safagress:11.5 .
This is image list:
PS D:\Software\Windows\Docker\Images\AndroidService> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
safagress 11.5 26d34fa7c2c1 About an hour ago 71.9MB
postgres 11.5-alpine 78b21f6420c0 5 days ago 71.9MB
alpine latest 961769676411 5 days ago 5.58MB
dpage/pgadmin4 latest 489972d75226 6 days ago 248MB
and make container :
docker run -d --name=pg-docker -p 5433:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123 safagres
and container list :
PS D:\Software\Windows\Docker\Images\AndroidService> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e4a6bdf49312 safagress:11.5 "docker-entrypoint.s…" About an hour ago Up About an hour 0.0.0.0:5433->5432/tcp pg-docker
3de509771297 dpage/pgadmin4 "/entrypoint.sh" 2 hours ago Up 2 hours 443/tcp, 127.0.0.1:8081->80/tcp priceless_black
PS D:\Software\Windows\Docker\Images\AndroidService>
1- When i am creating container i got this error:
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
2019-08-26 05:25:55.650 UTC [39] ERROR: syntax error at or near "psql" at character 88
2019-08-26 05:25:55.650 UTC [39] STATEMENT: /*--psql -U posgtres -p 5432
psql -U <username> -d <dbname> -1 -f <filename>.sql*/
psql -U posgtres -p 5432
CREATE DATABASE pglocations
WITH OWNER = postgres
ENCODING = 'UTF8'
LC_COLLATE = 'English_United States.1252'
TABLESPACE = pg_default
CONNECTION LIMIT = -1
TEMPLATE template0;
psql:/docker-entrypoint-initdb.d/init.sql:12: ERROR: syntax error at or near "psql"
LINE 4: psql -U posgtres -p 5432
2- How can i pass for example ENV DBNAME pglocations from dockerfile to init.sql to use it's value?
$DBNAME?