在docker上持久的postgres

docker工人开始使用我的数据库容器持久容器存储。 我认为创build一个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 

似乎工作,但是如何创build这里提到的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连接到数据库如下

 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 

但是,当我尝试在默认path的web界面连接时,似乎没有连接,尽pipe链接 (见上文)。

 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屏幕

@ 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