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

我正在尝试开始我的游戏! 2.4使用Docker-compose的Postgres数据库应用程序。

我设法开始我的戏剧! 应用程序(但它不能工作,因为它不能连接到数据库)。 我还设法使用image mdillon / postgis:9.4启动我的postgis数据库。

我的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; 

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

如果我运行我的docker数据库并手动运行init.sql脚本,我可以添加一个具有几何types的表作为列。

现在出现我的问题:如果我尝试使用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] padeDefaultEvolutionsApi - ERROR: type "geometry" does not exist 5.run_1 | Position: 150 [ERROR:0, SQLSTATE:42704] 

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

现在我不知道应该怎么做才能使它工作,任何线索都会很棒!

在拳头,我会告诉你如何configuration我的数据库(编辑文件进行连接),然后我如何configuration它发挥。

 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为postgres

 apt-get -y install pgadmin3 

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

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

这里是deffiniert谁和他们如何login

 # 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") 

我希望这是你所需要的。