我正在尝试使用 docker-compose 运行我的 Web 应用程序。
我的 Dockerfile
FROM golang:1.15
WORKDIR /goprojects/vnlist
COPY . .
RUN go get github.com/revel/revel
RUN go get github.com/revel/cmd/revel
RUN go get -d -v ./...
EXPOSE 9000
CMD [ "revel", "run", "-a", "vnlist" ]
My docker-compose.yml
version: '3.3'
services:
web:
build: .
ports:
- "9000:9000"
db:
image: "postgres"
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgresql123"
POSTGRES_DB: "vnlist_db"
volumes:
- db-data:/foo
volumes:
db-data:
DBsetup 文件
package models
import (
"fmt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
var DB *gorm.DB
var (
DB_HOST = "localhost"
DB_PORT = "5432"
DB_USER = "postgres"
DB_PASSWORD = "postgresql123"
DB_NAME = "vnlist_db"
DB_TIMEZONE = "Asia/Jakarta"
)
func InitDB() {
dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME)
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
fmt.Println("DB Error: ", err)
}
db.AutoMigrate(&VN{}, &User{})
DB = db
}
正如我们在最后几行中看到的,数据库无法连接。
我已尝试更改数据库的凭据,但问题仍然存在。
我的问题是,如何解决这个问题?
一只名叫tom的猫
相关分类