【问题标题】:Persistent postgres on dockerdocker 上的持久化 postgres
【发布时间】:2015-12-13 08:07:12
【问题描述】:

开始使用 docker 我为我的数据库容器试验了持久性容器存储。我认为创建一个 postgres-TeamCity 实例将是一项简单的任务。然而,在运行 kitematic 和 docker-machine 的 osx 上,在引用本地文件系统时存在一些关于权限的问题。使用持久化容器似乎可以解决这个问题。

尝试使用以下内容运行docker-compose up -d

teamcitydb:
  image: postgres:9.3
  ports:
    - "5432:5432"
  environment:
    - POSTGRES_USER=teamcity
    - POSTGRES_PASSWORD=mysecretpassword
  volumes_from:
    - pgdata
pgdata:
  image: cogniteev/echo
  command: echo 'Data Container for PostgreSQL'
  volumes:
    - /var/lib/postgresql/data

似乎有效,但是如何创建此处提到的 DB 模式? https://hub.docker.com/r/sjoerdmulder/teamcity/如果我手动执行:

SETUP_TEAMCITY_SQL="create role teamcity with login password 'teamcity';create database teamcity owner teamcity;"
POSTGRES_PASSWORD=mysecretpassword

docker run -it --link teamcity_teamcitydb_1:postgres --rm -e "SETUP_TEAMCITY_SQL=$SETUP_TEAMCITY_SQL" -e "PGPASSWORD=$POSTGRES_PASSWORD" postgres bash -c 'exec echo $SETUP_TEAMCITY_SQL |psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U teamcity'

我只收到表/关系已存在的错误。 怎么了?是否有可能在 ymal 文件中“包含”此语句?

Teamcity 与 DB 连接如下

teamcity:
 image: sjoerdmulder/teamcity
 ports:
   - "8111:8111"
 links:
   - teamcitydb
 environment:
   - TEAMCITY_DATA_PATH=/var/lib/teamcity
   - DB_HOSTNAME=db
   - DB_DATABASE=teamcitydb
   - DB_USERNAME=teamcitydb
   - DB_PASSWORD=teamcitydb
 volumes:
   - ./volumes/teamcity:/var/lib/teamcity

但是,当我尝试在网络界面上连接时假设默认路径,似乎没有连接,尽管链接(见上文)。

Could not connect to PostgreSQL server.
connection refused. check that the hostname and port are correct and that the postmaster is accepting tcp/ip connections.
SQL exception: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

【问题讨论】:

    标签: postgresql docker teamcity docker-compose


    【解决方案1】:

    @1: https://github.com/docker-library/docs/tree/master/postgres 指定如何扩展镜像 --> 自定义 dockerfile 增加了一些初始化.sql

    @2:这里使用 docker-machine ip

    此处为 docker-compose.yml 示例:https://github.com/dataplayground/tc/blob/master/docker-compose.yml

    【讨论】:

      猜你喜欢
      • 2019-08-12
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 2018-10-31
      • 1970-01-01
      • 2019-06-17
      相关资源
      最近更新 更多