Help access DB from inside container

hi everyone,

I am hariono from indonesia , i am newbie in docker.
I was deploy airflow in docker container but i should be connect oracle DB in other host.
i want airflow worker can access oracle db from inside container.
If i was changes network driver to “host”, container will failed
If you have solution, verry appreciate.

services:
  postgresql:
    image: docker.io/bitnami/postgresql:latest
    volumes:
      - 'postgresql_data:/bitnami/postgresql'
    environment:
      - POSTGRESQL_DATABASE=bitnami_airflow
      - POSTGRESQL_USERNAME=bn_airflow
      - POSTGRESQL_PASSWORD=bitnami1
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
  redis:
    image: docker.io/bitnami/redis:latest
    volumes:
      - 'redis_data:/bitnami'
    environment:
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
  airflow-scheduler:
    image: docker.io/bitnami/airflow:2
    network_mode: "host"
    environment:
      - AIRFLOW_COMPONENT_TYPE=scheduler
      - AIRFLOW_DATABASE_NAME=bitnami_airflow
      - AIRFLOW_DATABASE_USERNAME=bn_airflow
      - AIRFLOW_DATABASE_PASSWORD=bitnami1
      - AIRFLOW_EXECUTOR=CeleryExecutor
      - AIRFLOW_WEBSERVER_HOST=airflow
  airflow-worker:
    image: docker.io/bitnami/airflow:2
    environment:
      - AIRFLOW_COMPONENT_TYPE=worker
      - AIRFLOW_DATABASE_NAME=bitnami_airflow
      - AIRFLOW_DATABASE_USERNAME=bn_airflow
      - AIRFLOW_DATABASE_PASSWORD=bitnami1
      - AIRFLOW_EXECUTOR=CeleryExecutor
      - AIRFLOW_WEBSERVER_HOST=airflow
  airflow:
    image: docker.io/bitnami/airflow:2
    environment:
      - AIRFLOW_DATABASE_NAME=bitnami_airflow
      - AIRFLOW_DATABASE_USERNAME=bn_airflow
      - AIRFLOW_DATABASE_PASSWORD=bitnami1
      - AIRFLOW_EXECUTOR=CeleryExecutor
    ports:
      - '8080:8080'
volumes:
  postgresql_data:
    driver: local
  redis_data:
    driver: local

Docker services/containers inside a Docker network (explicit or implicit) can communicate with each other by service name (from compose), all ports are reachable. So you should probably use postgresql for your database host variable.

You expect the users to know which container should connect to the Oracle DB. You have multiple containers. 3 of them contains airflow. We can guess, and the one called “aiflow” would probably be a good guess, but if oyu want good and quick answers, you need to share good question. You mention using host network that makes the container fail, but you already have one containe rusing the host network so here is another time to guess.

Here is mine: Your “airflow” container has port mapping and you tried to add the network_mode: host to that too, which is not allowed as you either have host network or port mapping. Maybe I’m guessing wrong, but it is hard as you didn’t share any error message.

You didn’t share what is the problem with your connection to Oracle DB.

The image description on Dockerhub does not mention any other database than postgres.

We don’t know,

  • whether the image comes with everything required to access an oracle database,
  • or how to configure airflow to use an oracle database.

Either you wait until someone who actually uses this airflow image achieved what you try to do, and shares it with us, or you ask the airflow community. I feel its more likely to find users in an airflow community that know what needs to be done, than users in a docker forum where the majority doesn’t use airflow.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.