我對Docker-compose很新穎,我正在嘗試在docker上創建一個容器,在postgres 9.6上運行,並使用docker運行它。 然後,我希望能夠通過一些數據庫管理工具連接到數據庫。如何在docker centos 6上啓動postgres 9.6服務6 image
如果我運行:
docker-compose up
圖像建立正確,但我就不能連接到數據庫。
如果我刪除TTY:真和stdin_open:真形象建立,但隨後退出碼退出0
如果我跑碼頭工人運行 - 它-p 5432:5432 - -entypoint/bin/bash [image_name]然後我手動運行命令服務postgresql-9.6開始一切工作正常(直到我退出容器)。
有什麼建議嗎?
這裏是我的搬運工,撰寫文件:
networks{}
version: '2'
services:
postgres:
build:
context: ./src/test/docker/postgres
ports:
- "5432:5432"
stdin_open: true
tty: true
我的搬運工文件:
FROM centos:6
RUN yum -y install
https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-
centos96-9.6-3.noarch.rpm
RUN yum -y install postgresql96 postgresql96-server postgresql96-libs
postgresql96-contrib postgresql96-devel
# Initialize the database (not starting it yet)
RUN service postgresql-9.6 initdb
RUN su postgres
RUN echo "listen_addresses = '*'" >> /var/lib/pgsql/9.6/data/postgresql.conf
RUN echo "PORT = 5432" >> /var/lib/pgsql/9.6/data/postgresql.conf
RUN echo "local all all trust" > /var/lib/pgsql/9.6/data/pg_hba.conf
RUN echo "host all all 127.0.0.1/32 ident" >> /var/lib/pgsql/9.6/data/pg_hba.conf
RUN echo "host all all ::1/128 ident" >> /var/lib/pgsql/9.6/data/pg_hba.conf
RUN echo "host all all 0.0.0.0/0 md5" >> /var/lib/pgsql/9.6/data/pg_hba.conf
RUN exit
# Expose the PostgreSQL port
EXPOSE 5432
ENTRYPOINT service postgresql-9.6 start
非常感謝@Colwin!你的評論讓我走上了正確的道路。我不得不改變命令中的一條路徑,並將其作爲「postgres」用戶運行。請在你的回答中修改它:ENTRYPOINT [「sudo」,「 - u」,「postgres」,「/ usr/pgsql-9.6/bin/postgres」,「 - D」,「/ var/lib/pgsql /數據「,」 - p「,」5432「] – Sokrates
很高興我可以幫助@Sokrates。我已經用你的新入口點更新了我的答案。如果能解決您的問題,請您接受我的答案嗎? – Colwin
嗨@Colwin,我想,但看起來我沒有足夠的聲望去做。我對嗎? – Sokrates