Lxc crash (out-of-memory error)


I am running LXD version 4.8 on Ubuntu 16.04.

The following command crashes with an out-of-memory error:

yes | lxc launch ubuntu:18.04 my-container

Apparently, lxc tries to read from stdin and assumes
that what it reads is finite.

Here is some background and the use-case in which this
error (or feature?) occurs:

I have a script called exec-in-container.sh. This script
shall create a container, if it not already exists, and
execute a command in it. In pseudo-code:

if container does not exist then
    lxc launch ubuntu:18.04 my-container
lxc exec my-container -- some-command

If I need to run an interactive script inside the container,
occasionally I would like to automate it using the yes

yes | exec-in-container.sh some-interactive-command

This worked with LXD-3.9 but now it’s broken :frowning:

Any ideas?


1 Like

Yes, modern LXD reads YAML from stdin of lxc init and lxc launch and indeed just like most applications that support reading from stdin, it will store that stuff in memory, so piping something like yes isn’t a good idea :slight_smile:

If this becomes a problem in a script for example, just use lxc launch ... </dev/null

1 Like