我正在尝试使用 docker-compose 运行我的 Web 应用程序。我的 DockerfileFROM golang:1.15WORKDIR /goprojects/vnlistCOPY . .RUN go get github.com/revel/revelRUN go get github.com/revel/cmd/revelRUN go get -d -v ./...EXPOSE 9000CMD [ "revel", "run", "-a", "vnlist" ]My docker-compose.ymlversion: '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:/foovolumes: db-data:DBsetup 文件package modelsimport ( "fmt" "gorm.io/driver/postgres" "gorm.io/gorm")var DB *gorm.DBvar ( 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}正如我们在最后几行中看到的,数据库无法连接。我已尝试更改数据库的凭据,但问题仍然存在。我的问题是,如何解决这个问题?
- 1 回答
- 0 关注
- 151 浏览
添加回答
举报
0/150
提交
取消