Issue
Due to OS vulnerabilities present on based image python:3.8-slim-buster, I am trying to make a build based on redhat ubi8 based image.
I successfully build the image with the following dockerfile:
FROM registry.access.redhat.com/ubi8/python-38:1-107
ARG AIRFLOW_VERSION=2.4.1
ARG AIRFLOW_USER_HOME=/usr/local/airflow
ENV AIRFLOW_HOME=${AIRFLOW_USER_HOME}
RUN pip install -U pip setuptools wheel && \
pip install 'apache-airflow[crypto,celery,postgres,hive,jdbc]==2.4.1' \
--constraint "https://raw.githubusercontent.com/apache/airflow/constraints-2.4.1/constraints-3.8.txt"
COPY bin/start.sh /start.sh
COPY airflow/airflow.cfg /usr/local/airflow/airflow.cfg
USER root
RUN useradd -ms /bin/bash -d /usr/local/airflow airflow && \
chown -R airflow: /usr/local/airflow && \
chown -R airflow: /opt/app-root
USER airflow
COPY airflow/dags /usr/local/airflow/dags
COPY requirements.txt /tmp/requirements.txt
COPY entrypoint.sh /entrypoint.sh
RUN /entrypoint.sh install
SHELL ["/bin/bash", "-c"]
EXPOSE 8080 5555 8793
USER airflow
WORKDIR ${AIRFLOW_USER_HOME}
ENTRYPOINT /entrypoint.sh start
However when I tried to run the new image in the same docker-compose set up used with the previous debian based image, my container fails to connect to the postgresql database.
It seems to try to connect to the postgres DB: AIRFLOW__CORE__SQL_ALCHEMY_CONN=postgresql+psycopg2://airflow:airflow@label-postgres:5432/airflow It is stuck in wait: waiting for Postgres(label-postgres:5432)... 4/20
It is not an issue of the configuration of the docker-compose, the DB is fully accessible from the container. The previous Debian based image build, worked without issue with the same setup.
Does someone know if there is some specific behaviour with Redhat that is blocking the connection? or if there an issue with my dockerfile?
Solution
This in the Dockerfile fix it:
yum install -y nc
The issue with the connection was due to the absence of netcat on the base image. Before connection to the DB Airflow try get the database with netcat, and if the command is not available it doesn't return an error but just say it is waiting for the database
Answered By - kaless Answer Checked By - Clifford M. (WPSolving Volunteer)