连接播放!使用Docker-compose应用于postgres(使用Postgis)数据库

时间:2016-01-10 20:24:31

标签: postgresql playframework docker postgis docker-compose

我试图开始玩游戏! 2.4使用带有Docker-compose的Postgres数据库的应用程序。

我设法开始我的游戏!单独应用(但它不能工作,因为它无法连接到数据库)。我还设法使用图像mdillon / postgis启动我的postgis数据库:9.4。

我的 Dockerfile 是:

FROM mdillon/postgis:9.4

ADD init.sql /docker-entrypoint-initdb.d/

这是我的 init.sql 文件:

CREATE USER simon WITH PASSWORD 'mySecretPassword';
ALTER USER simon WITH SUPERUSER;

CREATE DATABASE ticketapp;
GRANT ALL PRIVILEGES ON DATABASE ticketapp TO simon;
\connect ticketapp simon
CREATE EXTENSION postgis;

CREATE DATABASE tests;
GRANT ALL PRIVILEGES ON DATABASE tests TO simon;
\connect tests simon
CREATE EXTENSION postgis;

(我认为没有必要创建扩展,因为它似乎已经完成了。)

如果我运行docker数据库并手动运行init.sql脚本,我可以添加一个带有Geometry类型的表作为列。

现在出现了我的问题:如果我尝试使用Docker-compose和以下 docker-compose.yml 文件链接我的两个服务:

5.run:
  image: 5.run
  ports:
    - "88:88"
  links:
    - dbHost

dbHost:
  image: my_postgres
  ports:
    - "5433:5433"
  expose:
    - "5433"

我收到以下错误:

dbHost_1 | LOG:  database system is ready to accept connections
dbHost_1 | ERROR:  relation "play_evolutions" does not exist at character 72
dbHost_1 | STATEMENT:  select id, hash, apply_script, revert_script, state, last_problem from play_evolutions where state like 'applying_%'
dbHost_1 | ERROR:  type "geometry" does not exist at character 150
dbHost_1 | STATEMENT:  CREATE TABLE frenchCities (
dbHost_1 |  cityId                    SERIAL PRIMARY KEY,
dbHost_1 |  city                      VARCHAR(255) NOT NULL,
dbHost_1 |  geographicPoint           GEOMETRY NOT NULL
dbHost_1 |  )
5.run_1  | [error] p.a.d.e.DefaultEvolutionsApi - ERROR: type "geometry" does not exist
5.run_1  |   Position: 150 [ERROR:0, SQLSTATE:42704]

请注意我的游戏!应用程序正在等待数据库准备就绪。

现在我不知道应该做些什么才能让它发挥作用,任何线索都会很棒!

1 个答案:

答案 0 :(得分:-1)

首先,我将向您展示如何配置我的数据库(编辑连接文件)以及我如何配置它。

sudo su
apt-get install scala   //is important for play

apt-get -y install postgresql
sudo -u postgres psql
\password postgres

CREATE USER andi WITH PASSWORD 'pw';
create TABLE play OWNER TO andi;

\q

gui for postgres

apt-get -y install pgadmin3

您必须编辑文件(root访问权限): 你必须在以下数据中写入md5。 您必须删除数据中的注释才能解释。

/etc/postgresql/9.4/main/pg_hba.conf

这里是deffiniert谁以及他们如何登录

# Database administrative login by Unix domain socket
local   all             postgres                                md5 // here

#here is deffiniert who and how they can log in
# TYPE DATABASE        USER            ADDRESS                 METHOD

#here is deffiniert who and how they can log in# "local" is for Unix domain socket connections only
#here is deffiniert who and how they can log inlocal   all       all     md5 

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5 //and here
host    all             andi             127.0.0.1/32            md5 //and here


# IPv6 local connections:
host    all             all             ::1/128                 md5

<强>

<强> build.sbt

import _root_.sbt.Keys._
import _root_.sbt._

name := """has"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  cache,
  javaWs,
  javaCore,
  javaJdbc,
  "com.github.nscala-time" %% "nscala-time" % "1.6.0",
  "org.postgresql" % "postgresql" % "9.3-1102-jdbc41",
  "jp.t2v" %% "play2-auth" % "0.13.0",
  "jp.t2v" %% "play2-auth-test" % "0.13.0" % "test",
  "org.webjars" % "bootstrap" % "3.3.5"
)
lazy val myProject = (project in file("."))
  .enablePlugins(PlayJava, PlayEbean)

val appDependencies = Seq(
  "mimerender" %% "mimerender" % "0.1.2"
)

<强> CONF / application.conf

play.crypto.secret = "aKr4Mfn!vKzDjfhfdJRsakgbPS35!!HVDldkosGHRT"

# The application languages
play.i18n.langs = [ "en" ]
db.default.user=andi
db.default.password="pw"
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/play"

#The following line define define the model folder. You have to add a folder called models in the app folder.
ebean.default = "models.*"

# Root logger:
logger.root=ERROR
play.evolutions.enabled=true
# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG

<强>项目/ plugins.sbt

通常你只取消注释最后一行。

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.4")

// Web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")

// Play enhancer - this automatically generates getters/setters for public fields
// and rewrites accessors of these fields to use the getters/setters. Remove this
// plugin if you prefer not to have this feature, or disable on a per project
// basis using disablePlugins(PlayEnhancer) in your build.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")

// Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
// enablePlugins(SbtEbean). Note, uncommenting this line will automatically bring in
// Play enhancer, regardless of whether the line above is commented out or not.
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")

我希望这就是你所需要的。