docker 上的持久性 postgres
Persistent postgres on docker
开始使用 docker 我为我的数据库容器试验了持久容器存储。我认为创建一个 postgres-TeamCity 实例是一项简单的任务。然而在 osx 运行ning kitematic 和 docker-machine 上,在引用本地文件系统时存在一些关于权限的问题。使用持久容器似乎可以解决这个问题。
尝试 运行 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'
我只收到 table / 关系已经存在的错误。 怎么了? ymal文件中是否有可能"include"这条语句?
Teamcity 连接到数据库如下
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 界面连接时 假设默认路径,似乎没有连接,尽管 link(见上文)。
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.
@1: https://github.com/docker-library/docs/tree/master/postgres 指定如何扩展图像 --> 自定义 docker 添加一些 initialization.sql
的文件
@2:这里使用docker-机器ip
示例 docker-compose.yml 此处:https://github.com/dataplayground/tc/blob/master/docker-compose.yml
开始使用 docker 我为我的数据库容器试验了持久容器存储。我认为创建一个 postgres-TeamCity 实例是一项简单的任务。然而在 osx 运行ning kitematic 和 docker-machine 上,在引用本地文件系统时存在一些关于权限的问题。使用持久容器似乎可以解决这个问题。
尝试 运行 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'
我只收到 table / 关系已经存在的错误。 怎么了? ymal文件中是否有可能"include"这条语句?
Teamcity 连接到数据库如下
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 界面连接时 假设默认路径,似乎没有连接,尽管 link(见上文)。
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.
@1: https://github.com/docker-library/docs/tree/master/postgres 指定如何扩展图像 --> 自定义 docker 添加一些 initialization.sql
的文件@2:这里使用docker-机器ip
示例 docker-compose.yml 此处:https://github.com/dataplayground/tc/blob/master/docker-compose.yml