title: docker containers in different named networks: curl: (7) Failed to connect to localhost port 9080: Connection refused
body: <p><strong>Problem Definition</strong></p>
  <p>I am trying to use two <code>docker-compose.yml</code> files (each in separate directories) on the same host machine, one for Airflow and the other for another application. I have put Airflow's containers in the same named network as my other app (see the below compose files) and confirmed using docker network inspect that the Airflow containers are in the network. However when I make a curl from the airflow worker container the my_keycloak server I get the following error:</p>
  <p><strong>Error</strong></p>
  <blockquote>
  <p>Failed to connect to localhost port 9080: Connection refused</p>
  </blockquote>
  <p><strong>Files</strong></p>
  <p><code>Airflow docker-compose.yml</code></p>
  <pre><code>version: '3'
  x-airflow-common:
    &amp;airflow-common
    image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:2.1.0}
    environment:
      &amp;airflow-common-env
      AIRFLOW__CORE__EXECUTOR: CeleryExecutor
      AIRFLOW__CORE__SQL_ALCHEMY_CONN: postgresql+psycopg2://airflow:airflow@postgres/airflow
      AIRFLOW__CELERY__RESULT_BACKEND: db+postgresql://airflow:airflow@postgres/airflow
      AIRFLOW__CELERY__BROKER_URL: redis://:@redis:6379/0
      AIRFLOW__CORE__FERNET_KEY: ''
      AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION: 'true'
      AIRFLOW__CORE__LOAD_EXAMPLES: 'true'
      AIRFLOW__API__AUTH_BACKEND: 'airflow.api.auth.backend.basic_auth'
    #added working directory and scripts folder 6-26-2021 CP
    volumes:
      - ./dags:/opt/airflow/dags
      - ./logs:/opt/airflow/logs
      - ./plugins:/opt/airflow/plugins
    user: &quot;${AIRFLOW_UID:-50000}:${AIRFLOW_GID:-50000}&quot;
    depends_on:
      redis:
        condition: service_healthy
      postgres:
        condition: service_healthy
  
  services:
    postgres:
      image: postgres:13
      environment:
        POSTGRES_USER: airflow
        POSTGRES_PASSWORD: airflow
        POSTGRES_DB: airflow
      volumes:
        - postgres-db-volume:/var/lib/postgresql/data
      #added so that airflow can interact with baton 6-30-2021 CP
      networks:
        - baton_docker_files_tempo
      healthcheck:
        test: [&quot;CMD&quot;, &quot;pg_isready&quot;, &quot;-U&quot;, &quot;airflow&quot;]
        interval: 5s
        retries: 5
      restart: always
  
    redis:
      image: redis:latest
      ports:
        - 6379:6379
      #added so that airflow can interact with baton 6-30-2021 CP
      networks:
        - baton_docker_files_tempo
      healthcheck:
        test: [&quot;CMD&quot;, &quot;redis-cli&quot;, &quot;ping&quot;]
        interval: 5s
        timeout: 30s
        retries: 50
      restart: always
  
    airflow-webserver:
      &lt;&lt;: *airflow-common
      command: webserver
      #changed from default of 8080 because of clash with baton docker services 6-26-2021 CP
      ports:
        - 50309:8080
      #added so that airflow can interact with baton 6-30-2021 CP
      networks:
        - baton_docker_files_tempo
      healthcheck:
        test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;--fail&quot;, &quot;http://localhost:50309/health&quot;]
        interval: 10s
        timeout: 10s
        retries: 5
      restart: always
  
    airflow-scheduler:
      &lt;&lt;: *airflow-common
      command: scheduler
      #added so that airflow can interact with baton 6-30-2021 CP
      networks:
        - baton_docker_files_tempo
      healthcheck:
        test: [&quot;CMD-SHELL&quot;, 'airflow jobs check --job-type SchedulerJob --hostname &quot;$${HOSTNAME}&quot;']
        interval: 10s
        timeout: 10s
        retries: 5
      restart: always
  
    airflow-worker:
      &lt;&lt;: *airflow-common
      command: celery worker
      #added so that airflow can interact with baton 6-30-2021 CP
      networks:
        - baton_docker_files_tempo
      healthcheck:
        test:
          - &quot;CMD-SHELL&quot;
          - 'celery --app airflow.executors.celery_executor.app inspect ping -d &quot;celery@$${HOSTNAME}&quot;'
        interval: 10s
        timeout: 10s
        retries: 5
      restart: always
  
    airflow-init:
      &lt;&lt;: *airflow-common
      command: version
      environment:
        &lt;&lt;: *airflow-common-env
        _AIRFLOW_DB_UPGRADE: 'true'
        _AIRFLOW_WWW_USER_CREATE: 'true'
        _AIRFLOW_WWW_USER_USERNAME: ${_AIRFLOW_WWW_USER_USERNAME:-airflow}
        _AIRFLOW_WWW_USER_PASSWORD: ${_AIRFLOW_WWW_USER_PASSWORD:-airflow}
      #added so that airflow can interact with baton 6-30-2021 CP
      networks:
        - baton_docker_files_tempo
  
    flower:
      &lt;&lt;: *airflow-common
      command: celery flower
      ports:
        - 5555:5555
      #added so that airflow can interact with baton 6-30-2021 CP
      networks:
        - baton_docker_files_tempo
      healthcheck:
        test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;--fail&quot;, &quot;http://localhost:5555/&quot;]
        interval: 10s
        timeout: 10s
        retries: 5
      restart: always
  
  volumes:
    postgres-db-volume:
  #added baton network so that airflow can communicate with baton cp 6-28-2021
  networks:
    baton_docker_files_tempo:
      external: true
  
  </code></pre>
  <p><code>other apps docker-compose file</code></p>
  <pre><code>version: &quot;3.7&quot;
  services:
    db:
      image: artifactory.redacted.com/docker/postgres:11.3
      ports:
        - 11101:5432
      environment:
        POSTGRES_PASSWORD: postgres
        POSTGRES_DB: keycloaks156
      networks:
        - tempo
    keycloak:
      image: registry.git.redacted.com/tempo23/tempo23-server/keycloak:${TEMPO_VERSION:-develop}
      container_name: my_keycloak
      environment:
        KEYCLOAK_USER: admin
        KEYCLOAK_PASSWORD: admin
        KEYCLOAK_DEFAULT_THEME: redacted
        KEYCLOAK_WELCOME_THEME: redacted
        PROXY_ADDRESS_FORWARDING: 'true'
        KEYCLOAK_FRONTEND_URL: http://localhost:9080/auth
        DB_VENDOR: postgres
        DB_ADDR: db
        DB_USER: postgres
        DB_PASSWORD: postgres
      ports:
        - 9080:8080
      networks:
        - tempo
      depends_on:
        - db
    db-migrate:
      image: registry.git.redacted.com/tempo23/tempo23-server/db-migrate:${TEMPO_VERSION:-develop}
      command: &quot;-url=jdbc:postgresql://db:5432/ -user=postgres -password=postgres -connectRetries=60 migrate&quot;
      restart: on-failure:3
      depends_on:
        - db
      networks:
        - tempo
  
    keycloak-bootstrap:
      image: registry.git.redacted.com/tempo23/tempo23-server/server-full:${TEMPO_VERSION:-develop}
      command: [&quot;keycloakBootstrap&quot;, &quot;--config&quot;, &quot;conf/single.conf&quot;]
      depends_on:
        - db
      restart: on-failure:10
      networks:
        - tempo
    server:
      image: registry.git.redacted.com/tempo23/tempo23-server/server:${TEMPO_VERSION:-develop}
      command: [ &quot;-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005&quot;, &quot;conf/single.conf&quot; ]
      environment:
        AKKA_PARALLELISM_MAX: &quot;2&quot;
        DB_THREADPOOL_SIZE: &quot;4&quot;
        UNSAFE_ENABLED: &quot;true&quot;
        DOCKER_BIND_HOST_ROOT: &quot;${BIND_ROOT}&quot;
        DOCKER_BIND_CONTAINER_ROOT: &quot;/var/lib/tempo2&quot;
        MESSAGING_HOST: &quot;server&quot;
        PUBSUB_TYPE: inmem
        TEMPOJOBS_DOCKER_TAG: registry.git.redacted.com/tempo23/tempo23-server/tempojobs:${TEMPO_VERSION:-develop}
        NUM_WORKER: 1
        ASSET_CACHE_SIZE: 500M
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock
        - &quot;${BIND_ROOT}:/var/lib/tempo2&quot;
      ports:
        - 2551:2551 # akka port
        - 8080:8080 # application http port
        - 8081:8081 # executor http port
        - 5005:5005 # debug port
      networks:
        - tempo
      restart: always
      depends_on:
        - db
  networks:
    tempo:
    
  
  
  </code></pre>