docker - 无法在Docker中连接到Airflow Web服务器

标签 docker localhost airflow

我正在尝试在docker中运行Apache Airflow,尽管网络服务器似乎已正确打开,但我仍可以从本地主机访问网络服务器。

Docker撰写

version: '3'
services:
  webserver:
    build: .
    container_name: data-webserver
    depends_on:
      - postgres
    volumes:
      - ./src:/src
    ports:
      - "8080:8080"
  postgres:
    image: postgres:latest
    container_name: data-postgres
    environment:
      - POSTGRES_USER=airflow
      - POSTGRES_PASSWORD=airflow
      - POSTGRES_DB=airflow
    ports:
        - "5432:5432"

Dockerfile
FROM ubuntu
ENV PYTHONUNBUFFERED 1
ADD . .
ADD ./docker_src/my_folder /etc
ENV PYTHONPATH "${PYTONPATH}:/maintenance:/database_utils:/utils"
RUN apt-get update && apt-get install -y python-pip mysql-server
RUN pip install -r docker_src/requirements.pip
CMD tail -f /dev/null

气流初始化:
airflow initdb

气流网络服务器:
airflow webserver -p 8080

气流网络服务器响应:
2019-04-26 08:10:13 +0000] [31] [INFO] Starting gunicorn 19.9.0
[2019-04-26 08:10:13 +0000] [31] [INFO] Listening at: http://0.0.0.0:8080 (31)
[2019-04-26 08:10:13 +0000] [31] [INFO] Using worker: sync
[2019-04-26 08:10:13 +0000] [36] [INFO] Booting worker with pid: 36
[2019-04-26 08:10:13,684] {__init__.py:51} INFO - Using executor SequentialExecutor
[2019-04-26 08:10:13 +0000] [37] [INFO] Booting worker with pid: 37
[2019-04-26 08:10:13,746] {__init__.py:51} INFO - Using executor SequentialExecutor
[2019-04-26 08:10:13 +0000] [41] [INFO] Booting worker with pid: 41
[2019-04-26 08:10:13 +0000] [42] [INFO] Booting worker with pid: 42
[2019-04-26 08:10:13,850] {__init__.py:51} INFO - Using executor SequentialExecutor
[2019-04-26 08:10:13,866] {__init__.py:51} INFO - Using executor SequentialExecutor
[2019-04-26 08:10:13,974] {__init__.py:305} INFO - Filling up the DagBag from /root/airflow/dags
[2019-04-26 08:10:14,058] {__init__.py:305} INFO - Filling up the DagBag from /root/airflow/dags
[2019-04-26 08:10:14,156] {__init__.py:305} INFO - Filling up the DagBag from /root/airflow/dags
[2019-04-26 08:10:14,164] {__init__.py:305} INFO - Filling up the DagBag from /root/airflow/dags
[2019-04-26 08:10:34 +0000] [31] [INFO] Handling signal: winch
[2019-04-26 08:10:35 +0000] [31] [INFO] Handling signal: winch
[2019-04-26 08:10:44 +0000] [31] [INFO] Handling signal: ttin
[2019-04-26 08:10:44 +0000] [56] [INFO] Booting worker with pid: 56
[2019-04-26 08:10:44,937] {__init__.py:51} INFO - Using executor SequentialExecutor
[2019-04-26 08:10:45,143] {__init__.py:305} INFO - Filling up the DagBag from /root/airflow/dags
[2019-04-26 08:10:45 +0000] [31] [INFO] Handling signal: ttou
[2019-04-26 08:10:45 +0000] [36] [INFO] Worker exiting (pid: 36)
[2019-04-26 08:11:16 +0000] [31] [INFO] Handling signal: ttin
[2019-04-26 08:11:16 +0000] [61] [INFO] Booting worker with pid: 61
[2019-04-26 08:11:16,198] {__init__.py:51} INFO - Using executor SequentialExecutor
[2019-04-26 08:11:16,441] {__init__.py:305} INFO - Filling up the DagBag from /root/airflow/dags
[2019-04-26 08:11:17 +0000] [31] [INFO] Handling signal: ttou
[2019-04-26 08:11:17 +0000] [37] [INFO] Worker exiting (pid: 37)
[2019-04-26 08:11:47 +0000] [31] [INFO] Handling signal: ttin
[2019-04-26 08:11:47 +0000] [66] [INFO] Booting worker with pid: 66
[2019-04-26 08:11:47,453] {__init__.py:51} INFO - Using executor SequentialExecutor
[2019-04-26 08:11:47,670] {__init__.py:305} INFO - Filling up the DagBag from /root/airflow/dags
[2019-04-26 08:11:48 +0000] [31] [INFO] Handling signal: ttou
[2019-04-26 08:11:48 +0000] [41] [INFO] Worker exiting (pid: 41)

当我从计算机上运行时:http://localhost:8080/尽管我在docker-compose中公开了端口,但仍无法访问网站。

问题出在哪里?

Docke ps输出
    CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS                    NAMES
9aa56948cdf6        analytics-etl_webserver   "/bin/sh -c 'tail -f…"   4 minutes ago       Up 4 minutes        0.0.0.0:8080->8080/tcp   data-webserver
20db5fd63ad8        postgres:latest           "docker-entrypoint.s…"   4 hours ago         Up 33 minutes       0.0.0.0:5432->5432/tcp   data-postgres

最佳答案

查看您的compose file,我们可以看到您尚未将webserver's容器端口(8080)映射到主机。

您的docker-compose.yml应该如下所示:

version: '3'
services:
  webserver:
    build: .
    container_name: data-webserver
    depends_on:
      - postgres
    volumes:
      - ./src:/src
    ports:
      - "8080:8080"
  postgres:
    image: postgres:latest
    container_name: data-postgres
    environment:
      - POSTGRES_USER=airflow
      - POSTGRES_PASSWORD=airflow
      - POSTGRES_DB=airflow
    ports:
        - "5432:5432"

关于docker - 无法在Docker中连接到Airflow Web服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55864776/

相关文章:

docker - Windows 和 Linux 容器同时运行 Windows 10

Android: "Bad Request-Invalid Hostname"从模拟器访问本地主机时

angular - 从其他机器访问本地主机 - Angular

snowflake-cloud-data-platform - 将 GCP Snowflake 连接到 Airflow 证书问题

airflow - 我如何编写一个具有与执行日期相关的动态任务集的 DAG?

docker - 具有不同API URL的Dockerized Vue SPA,具体取决于运行位置

docker - 如何在 Alpine Docker 镜像上安装 gdbserver 包?

docker - 如何引用存储在单独容器中的Flask HTML模板?

php - https 站点在本地打不开

python - 作为守护进程运行 Airflow 调度程序的问题