[英]Running airflow initdb raises error `"postgres" to address: Name or service not known` using postgres for airflow meta database
版本:
地形==.12
泊塢窗==19.03.8
蟒蛇==3.8
postgreSQL==9.6
阿帕奇氣流==1.10.10
描述:
目標是為 apache airflow 本地開發創建一個容器。 我使用 Postgres 數據庫作為后端來存儲 airflow 的元數據,因為它需要使用 Airflow LocalExecutor。 最后,我使用 Terraform 創建 Airflow 和 Postgres 容器。
問題:
該錯誤在dev_airflow
容器的 entrypoint.sh 中引發。 特別airflow initdb
引發了與 sql_alchemy_conn 字符串相關的錯誤。 sql_alchemy_conn 字符串在運行airflow initdb
之前作為環境變量導出。 sql_alchemy_conn 的值是有效的並且代表一個實時的 postgres 數據庫。
我試過這些 sql_alchemy_conn 字符串:
sql_alchemy_conn="postgresql://postgres_user:password@postgres:5432/postgres_db"
sql_alchemy_conn="postgresql+psycopg2://postgres_user:password@postgres:5432/postgres_db"
這導致了錯誤:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "postgres" to address: Name or service not known
我試過這些 sql_alchemy_conn 字符串:
sql_alchemy_conn="postgresql://postgres_user:password@localhost:5432/postgres_db"
sql_alchemy_conn="postgresql+psycopg2://postgres_user:password@localhost:5432/postgres_db"
這導致了錯誤:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
Terraform main.tf 用來組成docker個容器:
provider "docker"{}
resource "docker_image" "postgres" {
name = "postgres:9.6"
}
resource "docker_container" "postgres" {
image = docker_image.postgres.name
name = "postgres"
env = [
format("POSTGRES_USER=%s", var.postgres_user),
format("POSTGRES_PASSWORD=%s", var.postgres_password),
format("POSTGRES_DB=%s", var.postgres_db),
]
ports {
internal = var.postgres_port
}
}
resource "docker_image" "local_airflow" {
name = "local_airflow:latest"
keep_locally = false
}
resource "docker_container" "airflow" {
image = docker_image.local_airflow.name
name = "dev_airflow"
ports {
internal = 8080
external = 8080
}
env = [
format("AIRFLOW__CORE__EXECUTOR=%s", lookup(var.executor, var.environment)),
format("AIRFLOW__CORE__LOAD_EXAMPLES=%s", var.load_examples),
format("AIRFLOW__CORE__SQL_ALCHEMY_CONN=%s", var.sql_alchemy_conn)
]
volumes {
host_path = "/airflow/dags"
container_path = "/usr/local/airflow/dags"
}
volumes {
host_path = "/airflow/plugins"
container_path = "/usr/local/airflow/plugins"
}
depends_on = [docker_container.postgres]
command = ["webserver"]
entrypoint = ["/entrypoint.sh"]
healthcheck {
test = ["CMD-SHELL", "[ -f /usr/local/airflow/airflow-webserver.pid ]"]
interval = "30s"
timeout = "30s"
retries = 3
}
restart = "always"
}
也許這個資源部署在默認的 bridge.network 上。
嘗試創建一個 custom.network
https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources.network
然后,使用這個 output,運行這個容器 in.network https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container .networks_advanced -(可選,塊)參見下面的網絡高級. 如果此塊優先於 deprecated.network_alias 和 .network 屬性。
這與您使用 docker CLI 的方式相同。
docker network create foo
docker run --rm --network=foo bar
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.