首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在码头中心6映像上启动postgres 9.6服务

如何在码头中心6映像上启动postgres 9.6服务
EN

Stack Overflow用户
提问于 2017-08-01 08:28:56
回答 1查看 2.2K关注 0票数 2

我很新的对接-写作,我试图建立一个容器与postgres 9.6之上的centos 6,并运行它与码头组合。然后,我希望能够通过一些数据库管理工具连接到数据库。

如果我跑:

代码语言:javascript
复制
docker-compose up
  • 图像构建正确,但是我无法连接到数据库。
  • 如果删除tty:truestdin_open: true,则映像将生成,但退出代码为0。
  • 如果我运行-it -p 5432:5432 -entypoint /bin/bash image_name,然后手动运行命令service postgresql-9.6 start,一切都正常(直到退出容器)。

有什么建议吗?

这是我的码头-撰写文件:

代码语言:javascript
复制
networks{}
version: '2'
services:
    postgres:
        build:
          context: ./src/test/docker/postgres
        ports:
        - "5432:5432"
        stdin_open: true
        tty: true

我的码头档案:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-01 10:12:00

您的停靠文件中的ENTRYPOINT允许您将容器配置为可执行文件。这是一种包装您需要运行的容器中所有依赖项并运行容器=运行脚本/应用程序等的方法。

现在你的切入点

代码语言:javascript
复制
ENTRYPOINT service postgresql-9.6 start

只运行服务启动和退出!所以你的容器也会退出。如果要将其配置为可执行文件,则需要将postgres命令作为ENTRYPOINT命令运行。

代码语言:javascript
复制
  ENTRYPOINT ["sudo","-u","postgres","/usr/pgsql-9.6/bin/postgres","-D","‌​/var/lib/pgsql/9.6/d‌​ata","-p","5432"]

这将在容器启动时将postgres作为您的ENTRYPOINT命令运行,并且您应该能够连接到它。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45432697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档