这是我的 docker compose 文件
version: '3'
services:
magic:
image: mageai/mageai:latest
command: mage start ${PROJECT_NAME}
env_file:
- .env
build:
context: .
dockerfile: Dockerfile
environment:
ENV: dev
USER_CODE_PATH: /home/src/${PROJECT_NAME}
POSTGRES_DBNAME: ${POSTGRES_DBNAME}
POSTGRES_SCHEMA: ${POSTGRES_SCHEMA}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_HOST: ${POSTGRES_HOST}
POSTGRES_PORT: ${POSTGRES_PORT}
ports:
- 6789:6789
volumes:
- .:/home/src/
- ~/Documents/secrets/personal-gcp.json:/home/src/personal-gcp.json
restart: on-failure:5
postgres:
image: postgres:14
restart: on-failure
container_name: ${PROJECT_NAME}-postgres
env_file:
- .env
environment:
POSTGRES_DB: ${POSTGRES_DBNAME}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports:
- "${POSTGRES_PORT}:5432"
pgadmin:
image: dpage/pgadmin4
environment:
- [email protected]
- PGADMIN_DEFAULT_PASSWORD=root
ports:
- "8080:80"
这是我的 .env 文件
PROJECT_NAME=magic-zoomcamp
POSTGRES_DBNAME=postgres
POSTGRES_SCHEMA=magic
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
我尝试通过运行连接到 Postgres
(https://i.sstatic.net/M6b29VKp.png)
但每次都会遇到这些错误。
(https://i.sstatic.net/AJp0TTw8.png)
我该如何解决这个问题?
我希望我能知道我面临的问题的根本原因
您必须设置环境变量才能连接到数据库,这里是更正的属性:
POSTGRES_CONNECT_TIMEOUT: 10
POSTGRES_DBNAME: "{{ env_var('POSTGRES_DBNAME') }}"
POSTGRES_USER: "{{ env_var('POSTGRES_USER') }}"
POSTGRES_PASSWORD: "{{ env_var('POSTGRES_PASSWORD') }}"
POSTGRES_HOST: "{{ env_var('POSTGRES_HOST') }}"
POSTGRES_PORT: "{{ env_var('DB_PORT') }}"
你需要在
io_config.yaml
文件中配置它