How to run/execute commands in a LXD container using lxc

Fig.03: Run commands on in a container

Fig.03: Run commands on in a container

You can run or execute commands in the LXD container using lxc command as follows. The syntax is:
$ lxc exec container -- command
The above will run given command on Linux vm.

Run “date” command in a container named cenots-db

$ lxc exec cenots-db -- date
Mon Nov 7 13:19:25 UTC 2016

Run “ifconfig” command in a container named opensuse

$ lxc exec opensuse -- ifconfig
Sample outputs:

eth0      Link encap:Ethernet  HWaddr 00:16:3E:9B:D3:AA  
          inet addr:10.210.206.168  Bcast:10.210.206.255  Mask:255.255.255.0
          inet6 addr: fe80::216:3eff:fe9b:d3aa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:62 errors:0 dropped:0 overruns:0 frame:0
          TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:6288 (6.1 Kb)  TX bytes:1665 (1.6 Kb)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

Run “ip r” command in a container named ubuntu-nginx

$ lxc exec ubuntu-nginx -- ip r
default via 10.210.206.1 dev eth0

Run “cat /etc/debian_version” command in a container named file-server

$ lxc exec file-server -- cat /etc/debian_version
7.11

Run “dnf update” command in a container named fedora24-c1

$ lxc exec fedora24-c1 -- dnf update
Dependencies resolved.
Nothing to do.
Complete!

Examples and usage: How to install LXD container hypervisor on Ubuntu 16.04 LTS