cant init db for airflow docker-compose permission denied

Viewed 1218

I am trying to run the docker-compose file from the main airflow website and when I try to do docker-compose up airflow-init it fails and gives me:

airflow-init_1       |     with open(AIRFLOW_CONFIG, 'w') as file:
airflow-init_1       | PermissionError: [Errno 13] Permission denied: '/opt/airflow/airflow.cfg'

Most of the services show this same error, such as the flower_1, airflow-webserver_1, airflow-worker_1 and airflow-scheduler_1. It reaches the maximum 20 retires and gives up.

I tried to do chmod -R 777 on the directory where the airflow.cfg lives but same error comes up. In the docker-compose.yml file I have:

volumes:
  - ./airflow.cfg:/opt/airflow/airflow.cfg

I tried without mounting the airflow.cfg file but now I get this message:

 ValueError: Unable to configure handler 'processor': [Errno 13] Permission denied: '/opt/airflow/logs/scheduler'

I checked the directory permissions and it looks like this: drwxrwxrwx.

I'm not sure what else to try. I'm running on RHEL VM. Appreciate some help. Thanks.

2 Answers

Check the .env file that is located at the same level as the docker-compose file, you should have these variables declared:

AIRFLOW_UID=1000
AIRFLOW_GID=0`

The number of each variable has to correspond to the user_id and group_id of your OS from which you are running Airflow. In the terminal run this:

echo -e "AIRFLOW_UID=$(id -u)\nAIRFLOW_GID=0"

Then update the values in the .env file.

Also, you should check that every folder and file in the root Airflow folder, has the same user as owner, if not change it by running chown -r your_user:your_group.

Source here. Let me know if that worked for you

I added :z to the end of the mount, like:

volumes:
    - ./dags:/opt/airflow/dags:z
    - ./logs:/opt/airflow/logs:z
    - ./plugins:/opt/airflow/plugins:z

as shown in this github thread, and it magically works. I wasn't sure what the :z does until I found this other SO post that explains what it means.

Related