postgresql - docker 上的持久性 postgres

标签 postgresql docker teamcity docker-compose

开始使用 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

似乎可行,但是如何创建这里提到的数据库模式? 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

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

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.

web Screen

最佳答案

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

@2:这里使用docker-machine ip

在此处采样 docker-compose.yml:https://github.com/dataplayground/tc/blob/master/docker-compose.yml

关于postgresql - docker 上的持久性 postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34234858/

相关文章:

python - django postgresql 查询不工作

json - 如何在 postgres 中的 jsonb 单元格内按 limit 1 执行排序?

c# - 如何在Docker中运行32位.NET Core应用程序

docker - 在 docker 镜像中运行 jar 文件

c# - 在 Team City 上构建时,命名空间 'System.Data.Entity' 中不存在“验证”

python - Postgres : is set_config(). current_setting() 应用程序变量的私有(private)/稳健堆栈?

javascript - Node.js - 类型错误 : Client is not a constructor

python - 如何为自定义 python 项目编写 Dockerfile?

git - 如何在 TeamCity 构建步骤中设置 SSH 认证的 git 命令

git - 如果仅更改了特定文件,如何不触发 Teamcity 中的构建