Skip to content

Instantly share code, notes, and snippets.

@alanhoyle
Created April 12, 2019 21:01
Show Gist options
  • Save alanhoyle/767ea131401b6d151fd05d314248019d to your computer and use it in GitHub Desktop.
Save alanhoyle/767ea131401b6d151fd05d314248019d to your computer and use it in GitHub Desktop.
Simple script to check if the current shell is running in a linux container
#! /usr/bin/env sh
if [[ "$OSTYPE" == "linux-gnu" ]] ; then
if grep -q docker /proc/1/cgroup || test -e /.dockerenv ; then
echo DOCKER ;
elif grep -q lxc /proc/1/cgroup ; then
echo LXC ;
elif test -z ${SINGULARITY_CONTAINER+x} ; then
echo no_container ;
else
echo SINGUARITY ;
fi
else
echo 'unsupported OS: $OSTYPE != "linux-gnu"'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment