gpt4 book ai didi

postgresql - 连接游戏!使用 Docker-compose 应用到 postgres(带 Postgis)数据库

转载 作者:行者123 更新时间:2023-11-29 12:28:09 24 4
gpt4 key购买 nike

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

我设法开始我的游戏了!单独的应用程序(但它不起作用,因为它无法连接到数据库)。我还设法使用图像 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;

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

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

现在我的问题来了:如果我尝试将我的两个服务与 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]

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

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

最佳答案

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

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

postgres 的图形用户界面

apt-get -y install pgadmin3

您必须编辑文件(root 权限):您必须在以下数据中写入 md5。你必须删除你数据中的评论只是为了解释。

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

这里定义了谁可以登录以及他们如何登录

# 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

Play

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

project/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")

希望这就是您所需要的。

关于postgresql - 连接游戏!使用 Docker-compose 应用到 postgres(带 Postgis)数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34710386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com