Skip to content

bwrap has impact on the shell when finished #744

@immae

Description

@immae

It’s a bit difficult to explain the issue, so I’m giving a script below to reproduce it. It arises with docker but also "other container tools" (my first occurence occured with machinectl, but docker allows a more minimal example)

#!/usr/bin/env bash

if ! command -v bwrap || ! command -v docker; then
  echo "bubblewrap and docker are needed for this example"
  exit 1
fi

# Make sure we don't leave some running containers behind
container_id=$(docker run -d -it alpine)
trap "docker stop $container_id" EXIT

# This command works
echo "This docker command works"
docker exec -it "$container_id" ls -a

echo "Please exit the shell below to continue"
bwrap --unshare-pid --ro-bind-try /bin /bin --ro-bind-try /lib64 /lib64 --ro-bind-try /lib /lib --ro-bind-try /usr /usr --ro-bind-try /nix /nix -- /bin/sh

echo "This docker command doesn't work"
# Bash "backgrounds" the command instead of running docker. We are
# obliged to run "fg" to let it continue
docker exec -it "$container_id" ls -a

When I run this script, I get the following output:

host $ ./example.sh 
This docker command works
(some ls output)
Please exit the shell below to continue
$ 
This docker command doesn't work

[1]+  Stopped                 ./example.sh
host $ fg
./example.sh
(some ls output)
7e75ced3ecdf227d1eaad68d6dfc3e44587ae483ec124e09937628238a4d6560

The issue only happens when the "--unshare-pid" flag is present on bwrap (the rest of the flags is just to get a MVE). I could reproduce the issue on two different kinds of systems (debian and nixos). "Normal" (non-container related) commands work just fine. Also, we need to get an interactive shell with bwrap, otherwise the issue doesn’t arise either.

I searched for some information regarding that kind of behavior in vain, any pointer to an explanation / solution would be appreciated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions