Weird piping behavior in containers

Here’s an odd one: When I chain multiple pipes inside of a container, the producer hangs indefinitely instead of exiting when the consumers stop consuming.

As a concrete example,

# yes | fold | head -n 1

Prints one “y” and then halts on the host, as expected. But inside of a container, this command prints one “y”, but never exits. top shows that fold is locked at 100% single-core CPU usage. Neither the shell nor the base image seem to make a difference - I have tried various combinations of Debian, Ubuntu, bash, sh, and dash.

This is version 3.18 on Fedora, installed with snap. I’d like to figure out what’s going on because this behavior breaks shell scripts.


It looks like a tty issue.

user@mycomputer:~$ lxc exec mycontainer bash
root@mycontainer:~# yes | fold | head -n 1
root@mycontainer:~# tty
not a tty
root@mycontainer:~# exit
user@mycomputer:~$ lxc console mycontainer
To detach from the console, press: <ctrl>+a q

mycontainer login: root
Last login: Sun Nov  3 22:43:55 UTC 2019 on UNKNOWN
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-66-generic x86_64)

 * Documentation:
 * Management:
 * Support:

  System information as of Sun Nov  3 22:58:27 UTC 2019

  System load:    0.16      Memory usage: 0%   Processes:       20
  Usage of /home: unknown   Swap usage:   0%   Users logged in: 0

0 packages can be updated.
0 updates are security updates.

root@mycontainer:~# yes | fold | head -n 1
root@mycontainer:~# tty

Brilliant! Didn’t know you could bring up a proper tty.