[英]Running airflow initdb raises error `"postgres" to address: Name or service not known` using postgres for airflow meta database
Versions:版本:
Terraform==.12地形==.12
docker==19.03.8泊坞窗==19.03.8
python==3.8蟒蛇==3.8
postgreSQL==9.6 postgreSQL==9.6
apache-airflow==1.10.10阿帕奇气流==1.10.10
Description:描述:
The goal is to create a container for apache airflow local development.目标是为 apache airflow 本地开发创建一个容器。 I'm using a Postgres database as the backend to store metadata for airflow since it's required to use the Airflow LocalExecutor.
我使用 Postgres 数据库作为后端来存储 airflow 的元数据,因为它需要使用 Airflow LocalExecutor。 Lastly, I'm using Terraform to create Airflow and Postgres containers.
最后,我使用 Terraform 创建 Airflow 和 Postgres 容器。
Problem:问题:
The error is raised within the dev_airflow
container's entrypoint.sh.该错误在
dev_airflow
容器的 entrypoint.sh 中引发。 Specifically airflow initdb
raised an error related to the sql_alchemy_conn string.特别
airflow initdb
引发了与 sql_alchemy_conn 字符串相关的错误。 The sql_alchemy_conn string is exported as an env variable before running airflow initdb
. sql_alchemy_conn 字符串在运行
airflow initdb
之前作为环境变量导出。 The sql_alchemy_conn's values are valid and represent a live postgres database. sql_alchemy_conn 的值是有效的并且代表一个实时的 postgres 数据库。
I've tried these sql_alchemy_conn strings:我试过这些 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"
which resulted in the error:这导致了错误:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "postgres" to address: Name or service not known
I've tried these sql_alchemy_conn strings:我试过这些 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"
which resulted in the error:这导致了错误:
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 used to compose docker containers: 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"
}
Maybe this resources are deployed on default bridge.network.也许这个资源部署在默认的 bridge.network 上。
Try to create a custom.network尝试创建一个 custom.network
https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources.network https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources.network
and then, with this output, run this container in.network https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container .networks_advanced - (Optional, block) See Networks Advanced below for details.然后,使用这个 output,运行这个容器 in.network https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container .networks_advanced -(可选,块)参见下面的网络高级. If this block has priority to the deprecated.network_alias and.network properties.
如果此块优先于 deprecated.network_alias 和 .network 属性。
It's the same that you use with docker CLI.这与您使用 docker CLI 的方式相同。
docker network create foo
docker run --rm --network=foo bar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.