Docker Community Forums

Share and learn in the Docker community.

Python import source files from docker volumns can not distinct upper/lower cases in lib name


(Warterw) #1

Expected behavior

import python file should distinct upper and lower cases in their name

Actual behavior

not works well while these lib files placed on docker volumns

Information

  • the output of:
    not works well on both docker for mac and docker-machine

  • a reproducible case if this is a bug, Dockerfiles FTW

  • host distribution and version ( OSX 10.10.x, OSX 10.11.x, Windows, etc )
    OS X EI Capitan

Steps to reproduce the behavior

dir1 is a Volumn mounted from host

root@b1b4ed0580e3:/dir1# touch aaa.py
root@b1b4ed0580e3:/dir1# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

import Aaa
quit()
root@7746949754f3:/dir1# ls -l Aaa.pyc
-rw-r–r-- 1 1000 staff 93 Aug 17 03:21 Aaa.pyc

Change to non-volumn directory, work as expected.

cd /dir2

touch aaa.py

python

Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

import Aaa
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named Aaa

These is no such a problem on Ubuntu Hosted Docker, only happens in Mac Hosted Docker.


(David Sheets) #2

By default, OS X uses case-insensitive but case-preserving HFS+ for its file systems. What you are seeing is the behavior of the default native OS X file system. If you want case-sensitivity, you can either reformat/re-install your OS with a case-sensitive HFS+ file system which may cause issues with some Mac software that pointlessly relies on case-insensitivity. Your other option is to create a new ramdisk or volume on an external drive or empty local drive partition that uses the HFS+ case-sensitivity option.


(Adrian Moisey) #3

Python does support case-preserving, case-insensitive filesystems. If it knows that the filesystem is case-preserving and case-insensitive, it will handle module importing correctly.

Now that Docker on OSX is putting a case-preserving, case-insensitive in a Linux environment, I think Python is assuming that the filesystem is case-preserving, case-sensitive, which is causing this behaviour.

See: https://www.python.org/dev/peps/pep-0235/


(Warterw) #4

Thanks a lot @dsheets and @adrianmoisey
I’ve tried python on my OS X, it performs same as a Linux env, no case-insentive + case-preserving issue. I agree this issue is about file system case insentive, however, I was expecting same issue on OS X…

lai:tmp lai$ touch aaa.py
lai:tmp lai$
lai:tmp lai$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import Aaa
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named Aaa

quit()
lai:tmp lai$


(Adrian Moisey) #5

It doesn’t fail on OSX because Python knows that it’s on a case insensitive + case preserving filesystem. Read the link I posted in my previous post.