My init.sql file is :
CREATE USER postgres WITH PASSWORD '123qwe';
CREATE DATABASE gmta_database ;
GRANT ALL PRIVILEGES ON DATABASE gmta_database TO postgres;
And DockerFile is:
FROM postgres:latest
COPY init.sql /docker-entrypoint-initdb.d/
ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD 123qwe
ENV POSTGRES_DB docker_pg
EXPOSE 5432
COPY test_latest.sql /
VOLUME /var/lib/postgresql/data
RUN pg_restore -U postgres -d docker_pg < test_latest.sql
When I run with command docker build -t gmta-test-vol:1.0.0 . , I am getting error like this:
Sending build context to Docker daemon 358.4kB
Step 1/7 : FROM postgres:latest
---> b97bae343e06
Step 2/7 : COPY init.sql /docker-entrypoint-initdb.d/
---> Using cache
---> 6f275b44db01
Step 3/7 : ENV POSTGRES_USER postgres
---> Using cache
---> 039924093b36
Step 4/7 : ENV POSTGRES_PASSWORD 123qwe
---> Using cache
---> 5e636686a2f7
Step 5/7 : ENV POSTGRES_DB docker_pg
---> Using cache
---> 9c0a773c138c
Step 6/7 : COPY gtma_latest.sql /
---> Using cache
---> 8dd99f79b403
Step 7/7 : RUN pg_restore -U postgres -d docker_pg < gtma_latest.sql
---> Running in 1e0a85650eb1
pg_restore: error: connection to database "docker_pg" failed: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I want to create the database and restore the dump data with single docker command.
- How can I solved the problem?
- Is it possible RUN pg_store command without create the docker container?
Please help. Thanks in advance.