Permanent link to this article:


3 pings

Skip to comment form

  1. One advantage of overriding the ‘shell’ alias instead of using ‘ubuntu’ is that Bash completion keeps working with ‘shell’ (both for filling the command name and the names of the container)

    1. Indeed, that’s an issue. Using the snap package of LXD, it is not possible to edit /etc/bash_completion.d/lxc with the completion rules because this is a link into the read-only LXD image.
      What you can do instead, is take a copy of this file, then remove the link and place the actual file in place. By doing so, you can edit it and add new commands. To add ubuntu (as in lxc ubuntu mycontainer), search for shell in the completion file and add ubuntu in the list.

    • Makrand on May 9, 2020 at 06:25
    • Reply

    Nice Article! BTW, is there any way to login into non ubuntu containers are regular user?

    Also, do you work on development on LXC/D?

  2. Hi Simon;

    If ı create any alias in container’s .bashrc than I cant call this.

    For example:

    I added alias netp=’clear; netstat -pulten’ to .bashrc in container and source .bashrc.

    When I call ‘lxc exec u18base — bash -c “netp”‘, I take this error “bash: netp: command not found”

    If I call “lxc exec u18base — netp” than there is no error/warning on terminal.

    Have you any experience?

  3. Hi!

    When you run a command in a container like lxc exec u18base - netp, and you do not get any output, then it is highly likely that the command could not be found and did not run any. You do not get any stderr from lxc exec commands, just stdout.

    When you run lxc exec, it does not load up the user’s shell environment, therefore the alias netp is not found.

    On top of that, alias-es are not processed during non-interactive shells.

    I suggest to move from BASH aliases to BASH functions.

    lxc exec mycontainer -- bash -c 'netp() { clear; netstat -pulten; } ; netp'
  4. Thank you Simos. I follow you and all who work for LXC/LXD with great pleasure and excitement.

  1. […] We can now create a container that uses the nonetwork profile. When we run lxc launch, we specify the nonetwork profile, and use the default ubuntu container image (ubuntu:) which is currently Ubuntu 18.04 LTS. In a few months this will switch to Ubuntu 20.04 LTS. We are happy with any LTS container image. If you wanted to specify specifically Ubuntu 18.04 LTS, replace ubuntu: with ubuntu:18.04. Finally, we give the name withoutnetworking. Once the container is created, we lxc list it to verify there is no IP address and finally we get a shell into it with lxc ubuntu containername. […]

  2. […] install the official client in a LXD container. Create a container and get a shell into it. Then, download the Deb package and install it. The initial Deb package is really small. It just […]

  3. […] 8. Using command aliases in LXD to exec a shell – Mi blog lah! […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.