Airflow change port in docker compose

Viewed 2323

I have airflow running locally on port 8080 with the following docker-compose.yaml:

version: '3.7'
services:
    postgres:
        image: postgres:9.6
        environment:
            - POSTGRES_USER=airflow
            - POSTGRES_PASSWORD=airflow
            - POSTGRES_DB=airflow
        logging:
            options:
                max-size: 10m
                max-file: "3"

    webserver:
        image: puckel/docker-airflow:1.10.9
        restart: always
        depends_on:
            - postgres
        environment:
            - LOAD_EX=y
            - EXECUTOR=Local
        logging:
            options:
                max-size: 10m
                max-file: "3"
        volumes:
            - ./dags:/usr/local/airflow/dags
            # Add this to have third party packages
            - ./requirements.txt:/requirements.txt
            # - ./plugins:/usr/local/airflow/plugins
        ports:
            - "8080:8080"
        command: webserver
        healthcheck:
            test: ["CMD-SHELL", "[ -f /usr/local/airflow/airflow-webserver.pid ]"]
            interval: 30s
            timeout: 30s
            retries: 3

However I need the port 8080 for another process. I tried updating to both "8080:8081" and "8081:8081" but neither worked, server would not respond. "8080:8080", however, works like a charm. What am I missing here?

2 Answers

I think you missed the only correct option. The syntax for ports is:

{host : container}

so in your case

8081:8080

should technically work. Assuming of course that airflow runs on port 8080 and has that one exposed (which it seems according to the dockerfile).

You could change the HTTP port on the webserver command and update the Docker port mapping like this:

on the YAML:

...
    command: webserver -p 9999
    ports:
        - "9999:9999"

Sometimes this comes handy if you need the container to start listening directly on a specific port and avoid port mappings in scenarios where you are also changing network configurations e.g. in the YAML network_mode: host.

This basically means you can use only command: webserver -p 9999 and get rid of the ports: YAML completely.

Related