Skip to content

Commit

Permalink
cli: show error when popper run -e singularity runs in docker (#899)
Browse files Browse the repository at this point in the history
throw error message to notify users when attempting to use the singularity runner
when popper is being executed inside a docker container.

In order to identify this, the SingularityRunner constructor looks at /proc/1/cgroup
to check if docker folders are available, which is an indication that a process is 
being executed inside a docker container (https://stackoverflow.com/a/20012536)

The message instructs users to install popper via PIP instead.
  • Loading branch information
wtraylor committed Jul 30, 2020
1 parent 4098bc3 commit 906bc30
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/popper/runner_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ def __init__(self, init_spython_client=True, **kw):
self._spawned_containers = set()
self._s = None

if SingularityRunner._in_docker():
log.fail(
(
"You seem to be running Popper in a Docker container.\n"
"Singularity cannot be executed this way.\n"
"Either run Popper without Singularity or install Popper "
"through PIP.\n"
"Instructions are available here:\n"
"https://github.com/getpopper/popper/"
"blob/master/docs/installation.md"
)
)

if self._config.reuse:
log.fail("Reuse not supported for SingularityRunner.")

Expand Down Expand Up @@ -361,6 +374,13 @@ def _get_recipe_file(build_ctx_path, cid):
else:
log.fail("No Dockerfile was found.")

@staticmethod
def _in_docker():
""" Returns TRUE if we are being executed in a Docker container. """
if os.path.isfile("/proc/1/cgroup"):
with open("/proc/1/cgroup", "r") as f:
return "docker" in f.read() or "lxc" in f.read()

def _build_from_recipe(self, build_ctx_path, build_dest, cid):
SingularityRunner.lock.acquire()
pwd = os.getcwd()
Expand Down

0 comments on commit 906bc30

Please sign in to comment.