Docker for Mac limits the resource available to 2GB by default! This is too low for the app that I run. The solution is to increase the memory limit to 8GB, or however much your app needs.
(I am having similar issue albeit using a JVM application, not Python, and reached here by Google searching. From the deleted answer by @sergiu I am able to figure out the issue.)
Get started with Docker for Mac says:
Advanced settings are:
CPUs: By default, Docker for Mac is set to use half the number of processors available on the host machine. To increase processing power, set this to a higher number; to decrease, lower the number.
Memory: By default, Docker for Mac is set to use
2
GB runtime memory, allocated from the total available memory on your Mac. To increase RAM, set this to a higher number; to decrease it, lower the number.Swap: Configure swap file size as needed. The default is 1 GB.