Just a few hours ago I resolved similar problem I had encountered on my Docker image (i.e. Fenics crash on FunctionSpace calling). This thread helped me:
https://fenicsproject.discourse.group/t/error-running-demo-code/290
Basically what I did was:
apt-get -y install build-essential