简体   繁体   中英

Running airflow commands in Docker image error: [Errno 13] Permission denied: '/opt/airflow/logs/scheduler/

I'm creating an image on top of apache/airflow:latest from docker hub that copies over local dags and plugins. After building the local airflow image, I ran the command docker run -it local_airflow:latest list_dags to list the recently copied dags, but I get the output:

Unable to load the config, contains a configuration error.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/logging/config.py", line 565, in configure
    handler = self.configure_handler(handlers[name])
  File "/usr/local/lib/python3.6/logging/config.py", line 738, in configure_handler
    result = factory(**kwargs)
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/utils/log/file_processor_handler.py", line 50, in __init__
    os.makedirs(self._get_log_directory())
  File "/usr/local/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/opt/airflow/logs/scheduler/2020-09-03'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/airflow/.local/bin/airflow", line 25, in <module>
    from airflow.configuration import conf
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/__init__.py", line 47, in <module>
    settings.initialize()
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/settings.py", line 402, in initialize
    LOGGING_CLASS_PATH = configure_logging()
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/logging_config.py", line 68, in configure_logging
    raise e
  File "/home/airflow/.local/lib/python3.6/site-packages/airflow/logging_config.py", line 63, in configure_logging
    dictConfig(logging_config)
  File "/usr/local/lib/python3.6/logging/config.py", line 802, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/local/lib/python3.6/logging/config.py", line 573, in configure
    '%r: %s' % (name, e))
ValueError: Unable to configure handler 'processor': [Errno 13] Permission denied: '/opt/airflow/logs/scheduler/2020-09-03'

Here's the Dockerfile that builds on top of the base airflow image:

FROM apache/airflow:latest

USER airflow

ARG REQUIREMENTS_TXT=""
ENV REQUIREMENTS_TXT=${REQUIREMENTS_TXT}

COPY $REQUIREMENTS_TXT $REQUIREMENTS_TXT

ARG AIRFLOW_CONSTRAINTS_URL=""
ENV AIRFLOW_CONSTRAINTS_URL=${AIRFLOW_CONSTRAINTS_URL}

RUN if [ ! -z "${REQUIREMENTS_TXT}" ]; then pip install --user --upgrade pip && \
    pip install --user -r "${REQUIREMENTS_TXT}" \
    --constraint "${AIRFLOW_CONSTRAINTS_URL}"; fi

ARG DAGS_FOLDER="dags/"
ENV DAGS_FOLDER=${DAGS_FOLDER}

COPY dags/ $AIRFLOW_HOME/dags/

ARG PLUGINS_FOLDER="plugins/"
ENV PLUGINS_FOLDER=${PLUGINS_FOLDER}

COPY plugins/ $AIRFLOW_HOME/plugins/

Here's the docker build command

docker build . \
    --tag local_airflow:latest \
    --build-arg DAGS_FOLDER="dags/" \
    --build-arg PLUGINS_FOLDER="plugins/" 

The problem is that the owner for those files is (almost surely) root. Therefore you don't have the rights to change anything there.

I suggest to change the COPY command to look like this:

COPY --chown=airflow ... ...

This will change the ownership of the file/folder to airflow.

For more info check the documentation: https://docs.docker.com/engine/reference/builder/#copy

As mentioned in Docs: https://airflow.apache.org/docs/apache-airflow/stable/start/docker.html#initializing-environment

mkdir -p ./dags ./logs ./plugins
echo -e "AIRFLOW_UID=$(id -u)" > .env

AIRFLOW_UID=50000

Otherwise, files are created as the root users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM