Docker creates .dockerenv
and (removed in v1.11) files at the top of the container’s directory tree so you might want to check if those exist..dockerinit
Something like this should work.
#!/bin/bash
if [ -f /.dockerenv ]; then
echo "I'm inside matrix ;(";
else
echo "I'm living in real world!";
fi