开始使用 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.
最佳答案
@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/