I figured-out a solution myself:
After bootstrapping a fresh juju local environment, add a machine to the environment:
This shall create machine-1.
After the machine-1 is ready (check through
juju status), a juju template would have been created named similar to juju-trusty-lxc-template.
Now you can create clones of this template to create as many lxc-containers you want, and add them to juju environment manually (this can be created on a remote machine as well) through ssh.
sudo lxc-clone juju-trusty-lxc-template -n lxc-001
sudo lxc-clone juju-trusty-lxc-template -n lxc-002
Start the containers
sudo lxc-start -d -n lxc-001
sudo lxc-start -d -n lxc-002
and then add the the containers to juju through ssh
juju add-machine ssh:lxc-001 #this shall create machine-2
juju add-machine ssh:lxc-002 #this shall create machine-3
After juju finishes installing agents on the machine, you have to remove reference to localhost:170702 in agent.conf file inside containers and restart jujud inside continers. You can quickly do this through:
juju run --machine 2 'sudo sed -i "s/\- localhost:17070//" /var/lib/juju/agents/machine-*/agent.conf && sudo pkill jujud -hup'
juju run --machine 3 'sudo sed -i "s/\- localhost:17070//" /var/lib/juju/agents/machine-*/agent.conf && sudo pkill jujud -hup'
juju status if agents are in started state, and you are done, ready to deploy a service to these machines.
Hope this helps.
Note: In default juju configuration, lxc containers will get DHCP address from bridge created from juju. These addresses are not accessable on LAN. You may want to create a custom bridge and let juju use that (change
network-bridge: your-lan-br0 in ~/.juju/environments.yaml before bootstrapping). This is also necessary if you add a container from another physical machine. You may also want to configure static addresses for lxc-containers (dnsmasq).