Difference between revisions of "LXD/LXC Containers"
Tag: visualeditor-switched |
Tag: visualeditor-switched |
||
| Line 107: | Line 107: | ||
type: disk | type: disk | ||
| − | I followed https://blog.simos.info/ to add | + | I followed https://blog.simos.info/ to add X11 graphics to my containers in the profile. |
After the container is created you can see the log of cloud-init stuff in /var/log/cloud-init-output.log | After the container is created you can see the log of cloud-init stuff in /var/log/cloud-init-output.log | ||
Revision as of 20:30, 27 July 2021
- Creator/Maintainter: Yogan Naidoo (talk) - nTier Software Services
- Current Version: 1.0.0
- License: GPLv2
Credits
- Canonical Ltd
Background
I have just started dabbling with LXC containers and I am excited with my experience thus far. I find them easy to use with command line instructions. I like how lightweight these containers are and that one can use various Linux distros as the os of the container. So stopping, starting, creating, moving, copying and deleting are all easily achievable and happens quickly. I will document my use case below. My intention, however, is to introduce this technology to others so that more people can experiment with these containers. Ultimately more innovative use cases may be shared thus raising the productivity of our iDempiere community.
Resources
The following were helpful to me:
- Getting started with LXC containers - https://www.youtube.com/watch?v=CWmkSj_B-wo&list=PL34sAs7_26wPfLNZ5NKoH0RKbTAWMlh2I&index=2
- Beginners guide on using LXC profiles - Linux Containers - https://www.youtube.com/watch?v=ZEL1BSoUhSI&list=PL34sAs7_26wPfLNZ5NKoH0RKbTAWMlh2I&index=3
- LXD Containers backup, import, export, migrate between lxd instances - https://www.youtube.com/watch?v=RebZppmY8nw&list=PL34sAs7_26wPfLNZ5NKoH0RKbTAWMlh2I&index=4
- https://blog.simos.info/tag/lxd/
- LXD 4.0 quick recipe: LXC and KVM coexisting - https://discourse.ubuntu.com/t/lxd-4-0-quick-recipe-lxc-and-kvm-coexisting/15222
...used a major portion of this article's profile as my own
- https://linuxcontainers.org/lxd/advanced-guide/
- cloud-init Documentation - https://cloudinit.readthedocs.io/en/latest/
Aliases
I use the following aliases:
- lxc alias add login 'exec @ARGS@ --mode interactive -- /bin/sh -xac $@yogan - exec /bin/login -p -f '
...This allows me to log into a container with user name 'yogan' like: lxc login <container>
- lxc alias add delete 'delete -f'
- lxc alias add shell 'exec @ARGS@ -- bash
...This allows me to log into a container with 'root' like: lxc shell <container>
My Use Case
My personal laptop is the host. The os is Ubuntu 20.04.2 LTS. The MEGA/sources is where the various customer/idempiere repositories are. I share this with all new containers that are created.
I created a container called ID82z using os image: Ubuntu 20.04.2 LTS. I downloaded Eclipse, OpenJDK 11, maven, etc in here. Used the source from the shared directory.
I created another container called database using os image: Ubuntu 20.04.2 LTS. I downloaded PostgreSql 13 here. Changed the access port from 5432 and ensured that the db is available from outside.
So my lxc list looks like:
The Steps
- Install Lxd: snap install lxd
- LXD initial configuration: sudo /snap/bin/lxd init
...I chose the defaults and set the storage to 'dir'
- sudo usermod -a -G lxd <user>
...register your user into the lxd group and not to use sudo the entire time
- I set the Lxd network as follows: lxc network set lxdbr0 ipv4.address 172.16.0.1/24
Set the other properties similarly. This how my bridge network has been set up
- lxc launch images:ubuntu/focal/cloud
...I chose the image that has cloud-init support. This is important if you want cloud-init to automate some of your profile tasks
The Profile
The profile is the key to automate regular tasks when a container is built.
You can find my profile at: https://pastebin.com/AhAF2vVr
I found it a good idea to create your own file like default.yaml for your profile. I use this as my master file.
Then I update the default as follows
lxc profile edit default < default.yaml
This section in the profile is automatically creating a user and share my SSH public key. To copy the key, I had to 'cat' the key on the command line and copy the long key like that.
name: yogan ssh_authorized_keys:
Created a physical network called eth0 using dhcp
network: version: 1 config: - type: physical name: eth0 subnets: - type: dhcp
Copied some of my profiles so that my experience in these containers are the same as in the host
- cp /home/yogan/Downloads/.bashrc /root/.bashrc - cp /home/yogan/Downloads/.bashrc /home/yogan/.bashrc - cp /home/yogan/Downloads/.profile /root/.bash_profile - cp /home/yogan/Downloads/.profile /home/yogan/.bash_profile - cp /home/yogan/Downloads/.profile /root/.profile - cp /home/yogan/Downloads/.profile /home/yogan/.profile
Sharing some directories from the host with a new container
Downloadsdir: path: /home/yogan/Downloads source: /home/yogan/Downloads type: disk Sourcedir: path: /home/yogan/sources source: /home/yogan/MEGA/sources type: disk
I followed https://blog.simos.info/ to add X11 graphics to my containers in the profile.
After the container is created you can see the log of cloud-init stuff in /var/log/cloud-init-output.log
Run WooCommerce process from iDempiere
- Click on the menu item 'WooCommerce'
- Inspect your sales orders on iDempiere to see if your 'Completed' WooCommerce orders reflect
- The sales orders must be successfully completed on iDempiere
If you want to provide additional comments, please use the iDempiere forum post: iDempiere forum post
