IsADirectoryError: [Errno 21] Is a directory

You are here:
Estimated reading time: 1 min

Use Case

When you bind a single file in a Docker volume like that:

./mnt/airflow/airflow.cfg:/usr/local/airflow/airflow.cfg

You may end up with the following error:

IsADirectoryError

Cause

When Docker doesn’t find the file you want to bind from the Host, it creates an empty directory. In this example, since Docker doesn’t find the file ./mnt/airflow/airflow.cfg from the host, it creates an empty directory that will be bound to the file /usr/local/airflow/airflow.cfg in the Docker container.

Solution

Make sure you are using the latest version of Docker and Docker compose

First, check your Docker settings and make sure Docker can access your file as shown in “Shared Folders” or “File Sharing”

On Windows:

Docker shared folders on Windows

Here, the file you want to bind should be in the folder or subfolders of C:/Users (i.e: C:/Users/myname/documents/airflow.cfg)

On windows, you HAVE TO put the file or folder you want to bind in Docker, under the folder or subfolders of C:/Users

On Mac:

Docker file shared on Mac

Once your file is in a subfolder of a shared folder, you can move forward

Retry without changing anything, to verify if it works now you have shared the correct folder. If it doesn’t work,

Try to run your docker container like that:

docker run airflow -p 8080:8080 -v /${pwd}/mnt/airflow/airflow.cfg:/usr/local/airflow/airflow.cfg

If it doesn’t work, try the absolute path

docker run airflow -p 8080:8080 -v /home/user/my_files/mnt/airflow/airflow.cfg:/usr/local/airflow/airflow.cfg
For Windows user

Try:

docker run airflow -p 8080:8080 -v "/c/Users/Program Files/mnt/airflow/airflow.cfg:/usr/local/airflow/airflow.cfg"

If there is spaces in your path, you must use double quotes. Don’t use C:/my/path/:/usr/local/airflow as Docker will detect two “:” which won’t work. That’s why you have to use /c/ instead of C:/

Was this article helpful?
Dislike 5
Views: 4851