Из postgres стандартных образов я устанавливаю postgis, и после того, как я должен запустить psql, команда CREATE EXTENSION POSTGIS. Я думаю, что моя проблема - установить правильный параметр -h в команде psql, но я не уверен в этом. Есть идеи?
FROM postgres:12.1
MAINTAINER xxx
#ARG A_DB_USER='postgres'
#ARG A_DB_PASS='postgres'
ARG A_DB_NAME='postgres'
ARG A_TZ='Europe/Zurich'
#ENV DB_USER=${A_DB_USER}
#ENV DB_PASS=${A_DB_PASS}
ENV DB_NAME=${A_DB_NAME}
ENV TZ=${A_TZ}
# Adjusting Timezone in the system
RUN echo $TZ > /etc/timezone && \
apt-get update && apt-get install -y tzdata && \
rm /etc/localtime && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata && \
apt-get clean
# install postgis
RUN apt-get update && \
apt-get install -y postgis && \
apt-get clean
USER postgres
#Add password "postgres" to user postgres, create db, add .sql
RUN /etc/init.d/postgresql start && psql -U postgres -d mydb -h localhost -c "CREATE EXTENSION postgis;"
EXPOSE 5432
Ошибка: psql: error: could not connect to server: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
ERROR: Service 'istsos-db' failed to build: The command '/bin/sh -c /etc/init.d/postgresql start && psql -U postgres -d istsos -h localhost -c "CREATE EXTENSION postgis;"' returned a non-zero code: 2
РЕДАКТИРОВАТЬ: я запускаю его с docker -композицией
version: '3.7'
services:
app-db:
build:
context: ./
dockerfile: Dockerfile-pg
image: app-pg:1.0.0
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: app
POSTGRES_DB: app-db
volumes:
- ./docker-entrypoint-initdb.d/init-user-db.sh:/docker-entrypoint-initdb.d/init-user-db.sh
- v-app-pgdata:/var/lib/postgresql
- v-app-pglog:/data/var/log/postgresql
- v-app-pgconf:/etc/postgresql
app-main:
build:
context: ./
dockerfile: Dockerfile-tar-cp
image: app-main:1.0.0
restart: always
ports:
- 80:80
volumes:
v-app-pgdata:
name: v-app-pgdata
v-app-pglog:
name: v-app-pglog
v-app-pgconf:
name: v-app-pgconf
Я пытался использовать POSTGRES_DB: app-db
и указать psql -h app-db
Но docker -build возвращает: No PostgreSQL clusters exist; see "man pg_createcluster" ... (warning).
psql: error: could not connect to server: could not translate host name "app-db" to address: Name or service not known
ERROR: Service 'app-db' failed to build: The command '/bin/sh -c /etc/init.d/postgresql start && psql -U postgres -d app -h app-db -c "CREATE EXTENSION postgis;"' returned a non-zero code: 2
Я также пытаюсь с localhost безуспешно. Есть идеи?