使用 postgres、golang 和 Debian 11、Agora appbuilder 后端运行 Docker 容器或 docker compose 时出错

使用 postgres、golang 和 Debian 11、Agora appbuilder 后端运行 Docker 容器或 docker compose 时出错

我在 AWS 上启动了一个 Debian 11 EC2,并在其上安装了 postgres 14.5 以及 docker 和 docker compose。我为 postgres 添加了“admin”超级用户并使用密码。我创建了 docker-compose.yml 文件和 .env 文件。

当我尝试使用 docker-compose.yml 文件时,我得到:

sudo docker compose up -d
services.database.environment must be a mapping

当我用以下方式构建docker容器时

sudo docker build . -t tvappbuilder:latest

然后尝试使用以下命令运行它:

sudo docker run -p 8080:8080 tvappbuilder:latest --env-file .env -it
Config Path .
4:47PM INF server/utils/logging.go:105 > logging configured fileLogging=true fileName=app-builder-logs logDirectory=./logs maxAgeInDays=0 maxBackups=0 maxSizeMB=0
4:47PM FTL server/cmd/video_conferencing/server.go:71 > Error initializing database error="pq: Could not detect default username. Please provide one explicitly"

到目前为止,码头工人的情况如下:

sudo docker image list
REPOSITORY     TAG       IMAGE ID       CREATED         SIZE
<none>         <none>    6e5f035abda5   18 hours ago    1.82GB
tvappbuilder   latest    6166e24a47e0   21 hours ago    21.8MB
<none>         <none>    cedcaf2facd1   21 hours ago    1.82GB
hello-world    latest    feb5d9fea6a5   12 months ago   13.3kB
golang         1.15.1    9f495162f677   2 years ago     839MB

这是docker-compose.yml:

version: 3.7
services:
    server:
        container_name: server
        build: .
        depends_on:
            - database
        ports:
           - 8080:8080
        environment:
            - APP_ID: $APP_ID
            - APP_CERTIFICATE: $APP_CERTIFICATE
            - CUSTOMER_ID: $CUSTOMER_ID
            - CUSTOMER_CERTIFICATE: $CUSTOMER_CERTIFICATE
            - BUCKET_NAME: $BUCKET_NAME
            - BUCKET_ACCESS_KEY: $BUCKET_ACCESS_KEY
            - BUCKET_ACCESS_SECRET: $BUCKET_ACCESS_SECRET
            - CLIENT_ID: $CLIENT_ID
            - CLIENT_SECRET: $CLIENT_SECRET
            - PSTN_USERNAME: $PSTN_USERNAME
            - PSTN_PASSWORD: $PSTN_PASSWORD
            - SCHEME: $SCHEME
            - ALLOWED_ORIGIN: ""
            - ENABLE_NEWRELIC_MONITORING: false
            - RUN_MIGRATION: true
            - DATABASE_URL: postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@database:5432/$POSTGRES_DB?sslmode=disable

    database:
        container_name: server_database
        image: postgres-14.5
        restart: always
        hostname: database
        environment: 
            - POSTGRES_USER: $POSTGRES_USER
            - POSTGRES_PASSWORD: $POSTGRES_PASSWORD
            - POSTGRES_DB: $POSTGRES_DB

这是 .env 文件:

ENCRYPTION_ENABLED=0
POSTGRES_USER=admin
POSTGRES_PASSWORD=<correct pswd for admin>
POSTGRES_DB=tvappbuilder
APP_ID=<my real app ID>
APP_CERTIFICATE=<my real app cert>
CUSTOMER_ID=<my real ID>
CUSTOMER_CERTIFICATE=<my real cert>
RECORDING_REGION=0
BUCKET_NAME=<my bucket name>
BUCKET_ACCESS_KEY=<my real key>
BUCKET_ACCESS_SECRET=<my real secret>
CLIENT_ID=
CLIENT_SECRET=
PSTN_USERNAME=
PSTN_PASSWORD=
PSTN_ACCOUNT=
PSTN_EMAIL=
SCHEME=esports1_agora
ENABLE_SLACK_OAUTH=0
SLACK_CLIENT_ID=
SLACK_CLIENT_SECRET=
GOOGLE_CLIENT_ID=
ENABLE_GOOGLE_OAUTH=0
GOOGLE_CLIENT_SECRET=
ENABLE_MICROSOFT_OAUTH=0
MICROSOFT_CLIENT_ID=
MICROSOFT_CLIENT_SECRET=
APPLE_CLIENT_ID=
APPLE_PRIVATE_KEY=
APPLE_KEY_ID=
APPLE_TEAM_ID=
ENABLE_APPLE_OAUTH=0
PAPERTRAIL_API_TOKEN=<my real token>

根据这个:https://pkg.go.dev/github.com/lib/pq 我可能不需要使用 pq,而是直接使用 postgres,但看起来它是这样设置的。

非常感谢您的指点!

答案1

错误是:

services.database.environment must be a mapping

这告诉你...的价值

version: 3.7
services:
    server:
        ...
        environment:   # <-- THIS KEY HERE

需要映射(又称字典),但您已提供列表。您想要:

version: 3.7
services:
    server:
        container_name: server
        build: .
        depends_on:
            - database
        ports:
           - 8080:8080
        environment:
          APP_ID: $APP_ID
          APP_CERTIFICATE: $APP_CERTIFICATE
          CUSTOMER_ID: $CUSTOMER_ID
          CUSTOMER_CERTIFICATE: $CUSTOMER_CERTIFICATE
          BUCKET_NAME: $BUCKET_NAME
          BUCKET_ACCESS_KEY: $BUCKET_ACCESS_KEY
          BUCKET_ACCESS_SECRET: $BUCKET_ACCESS_SECRET
          CLIENT_ID: $CLIENT_ID
          CLIENT_SECRET: $CLIENT_SECRET
          PSTN_USERNAME: $PSTN_USERNAME
          PSTN_PASSWORD: $PSTN_PASSWORD
          SCHEME: $SCHEME
          ALLOWED_ORIGIN: ""
          ENABLE_NEWRELIC_MONITORING: false
          RUN_MIGRATION: true
          DATABASE_URL: postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@database:5432/$POSTGRES_DB?sslmode=disable

相关内容