Linux Containers: Difference between revisions
Jump to navigation
Jump to search
Line 86: | Line 86: | ||
==Create Alias== | ==Create Alias== | ||
{| | {| | ||
|valign="top"| | |||
<source lang='bash'> | |||
lxc launch images:alpine/3.17 academia && | |||
lxc exec academia sh <<'EOF' | |||
sleep 5 | |||
apk --no-cache add curl openjdk11 | |||
java -version | |||
EOF | |||
</source> | |||
---- | |||
'''create alias:''' | |||
lxc stop academia | |||
lxc publish academia --alias\ | |||
alpine/3.17:curl:java | |||
'''create alias from snapshot:''' | |||
lxc snapshot '''academia curl:java''' && | |||
lxc publish '''academia/curl:java''' --alias\ | |||
alpine/3.17:curl:java | |||
lxc delete academia | |||
'''launch alias:''' | |||
lxc launch '''alpine/3.17:curl:java''' academia && | |||
lxc exec academia bash | |||
lxc stop academia && lxc delete academia | |||
|valign="top"| | |valign="top"| | ||
<source lang='bash'> | <source lang='bash'> | ||
Line 112: | Line 138: | ||
lxc stop agronomy && lxc delete agronomy | lxc stop agronomy && lxc delete agronomy | ||
|valign="top"| | |||
<source lang='bash'> | |||
lxc launch images:oracle/9 economia && | |||
lxc exec economia bash <<'EOF' | |||
sleep 5 | |||
zypper install -y curl java-11-openjdk | |||
java -version | |||
EOF | |||
</source> | |||
---- | |||
'''create alias:''' | |||
lxc stop economia | |||
lxc publish economia --alias\ | |||
oracle/9:curl:java | |||
'''create alias from snapshot:''' | |||
lxc snapshot '''economia curl:java''' && | |||
lxc publish '''economia/curl:java''' --alias\ | |||
oracle/9:curl:java | |||
lxc delete economia | |||
'''launch alias:''' | |||
lxc launch '''oracle/9:curl:java''' economia && | |||
lxc exec economia bash | |||
lxc stop economia && lxc delete economia | |||
|- | |||
|colspan="3"| | |||
---- | |||
---- | |||
|- | |||
|valign="top"| | |valign="top"| | ||
<source lang='bash'> | <source lang='bash'> | ||
Line 163: | Line 220: | ||
lxc exec software bash | lxc exec software bash | ||
lxc stop software && lxc delete software | lxc stop software && lxc delete software | ||
|valign="top"| | |||
<source lang='bash'> | |||
lxc launch images:archlinux travelia && | |||
lxc exec travelia sh <<'EOF' | |||
sleep 5 | |||
pacman --noconfirm -S curl jre11-openjdk | |||
java -version | |||
EOF | |||
</source> | |||
---- | |||
'''create alias:''' | |||
lxc stop travelia | |||
lxc publish travelia --alias\ | |||
archlinux:curl:java | |||
'''create alias from snapshot:''' | |||
lxc snapshot '''travelia curl:java''' && | |||
lxc publish '''travelia/curl:java''' --alias\ | |||
archlinux:curl:java | |||
lxc delete travelia | |||
'''launch alias:''' | |||
lxc launch '''archlinux:curl:java''' travelia && | |||
lxc exec travelia bash | |||
lxc stop travelia && lxc delete travelia | |||
|} | |} | ||
Revision as of 00:38, 29 December 2022
sudo apt upgrade && sudo apt autoremove sudo snap install lxd --channel=4.0/stable
sudo snap start lxd sudo snap stop lxd sudo snap logs lxd
Initial Setup
sudo lxd init
:'
Would you like to use LXD clustering? (yes/no) [default=no]: yes
What IP address or DNS name should be used to reach this node? [default=10.20.21.10]:
Are you joining an existing cluster? (yes/no) [default=no]:
What name should be used to identify this node in the cluster? [default=ubuntu]: academia
Setup password authentication on the cluster? (yes/no) [default=no]:
Do you want to configure a new local storage pool? (yes/no) [default=yes]:
Name of the storage backend to use (btrfs, dir, lvm, zfs) [default=zfs]:
Create a new ZFS pool? (yes/no) [default=yes]:
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:
Size in GB of the new loop device (1GB minimum) [default=25GB]: 100GB
Do you want to configure a new remote storage pool? (yes/no) [default=no]:
Would you like to connect to a MAAS server? (yes/no) [default=no]:
Would you like to configure LXD to use an existing bridge or host interface? (yes/no) [default=no]:
Would you like to create a new Fan overlay network? (yes/no) [default=yes]:
What subnet should be used as the Fan underlay? [default=auto]:
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]:
'
Instance Management
lxc image list images: ubuntu amd64 lxc image list images: ubuntu arm64 lxc image list images: ubuntu
lxc launch images:alpine/3.15 academia --vm lxc launch images:alpine/3.15 academia lxc restart academia lxc start academia lxc stop academia |
lxc launch images:opensuse/15.3 agronomy --vm lxc launch images:opensuse/15.3 agronomy lxc restart agronomy lxc start agronomy lxc stop agronomy |
lxc launch images:apertis/v2020 robotics lxc launch images:apertis/v2021 robotics lxc restart robotics lxc start robotics lxc stop robotics |
lxc list -c nsS lxc list
lxc exec academia -- su --login chorke lxc exec academia -- /bin/sh lxc exec academia sh lxc console academia
download from container to host lxc file pull academia/etc/hosts ./ upload into container from host lxc file push -r ~/.ssh/ academia/root/.ssh/ lxc file push ~/.ssh/known_hosts academia/root/.ssh/
lxc stop academia && lxc delete academia lxc delete academia --force
manipulate remote images lxc image refresh ubuntu:21.04 lxc image delete ubuntu:21.04 lxc image show ubuntu:21.04 lxc image edit ubuntu:21.04
manipulate local images lxc image delete 97c97f4a1d2d lxc image delete a7b1071c0609
Create Alias
lxc launch images:alpine/3.17 academia &&
lxc exec academia sh <<'EOF'
sleep 5
apk --no-cache add curl openjdk11
java -version
EOF
create alias: lxc stop academia lxc publish academia --alias\ alpine/3.17:curl:java create alias from snapshot: lxc snapshot academia curl:java && lxc publish academia/curl:java --alias\ alpine/3.17:curl:java lxc delete academia launch alias: lxc launch alpine/3.17:curl:java academia && lxc exec academia bash lxc stop academia && lxc delete academia |
lxc launch images:opensuse/15.3 agronomy &&
lxc exec agronomy bash <<'EOF'
sleep 5
zypper install -y curl java-11-openjdk
java -version
EOF
create alias: lxc stop agronomy lxc publish agronomy --alias\ opensuse/15.3:curl:java create alias from snapshot: lxc snapshot agronomy curl:java && lxc publish agronomy/curl:java --alias\ opensuse/15.3:curl:java lxc delete agronomy launch alias: lxc launch opensuse/15.3:curl:java agronomy && lxc exec agronomy bash lxc stop agronomy && lxc delete agronomy |
lxc launch images:oracle/9 economia &&
lxc exec economia bash <<'EOF'
sleep 5
zypper install -y curl java-11-openjdk
java -version
EOF
create alias: lxc stop economia lxc publish economia --alias\ oracle/9:curl:java create alias from snapshot: lxc snapshot economia curl:java && lxc publish economia/curl:java --alias\ oracle/9:curl:java lxc delete economia launch alias: lxc launch oracle/9:curl:java economia && lxc exec economia bash lxc stop economia && lxc delete economia |
| ||
lxc launch images:fedora/37 robotics &&
lxc exec robotics bash <<'EOF'
sleep 5
dnf install -y curl java-11-openjdk
java -version
EOF
create alias: lxc stop robotics lxc publish robotics --alias\ fedora/37:curl:java create alias from snapshot: lxc snapshot robotics curl:java && lxc publish robotics/curl:java --alias\ fedora/37:curl:java lxc delete robotics launch alias: lxc launch fedora/37:curl:java robotics && lxc exec robotics bash lxc stop robotics && lxc delete robotics |
lxc launch images:ubuntu/22.04 software &&
lxc exec software bash <<'EOF'
sleep 5
apt-get install -y curl openjdk-11-jdk
java -version
EOF
create alias: lxc stop software lxc publish software --alias\ ubuntu/22.04:curl:java create alias from snapshot: lxc snapshot software curl:java && lxc publish software/curl:java --alias\ ubuntu/22.04:curl:java lxc delete software launch alias: lxc launch ubuntu/22.04:curl:java software && lxc exec software bash lxc stop software && lxc delete software |
lxc launch images:archlinux travelia &&
lxc exec travelia sh <<'EOF'
sleep 5
pacman --noconfirm -S curl jre11-openjdk
java -version
EOF
create alias: lxc stop travelia lxc publish travelia --alias\ archlinux:curl:java create alias from snapshot: lxc snapshot travelia curl:java && lxc publish travelia/curl:java --alias\ archlinux:curl:java lxc delete travelia launch alias: lxc launch archlinux:curl:java travelia && lxc exec travelia bash lxc stop travelia && lxc delete travelia |
Knowledge
lxc list snap info lxd journalctl -xe snap revert lxd snap list --all lxd sudo snap remove lxd journalctl -u snap.lxd.daemon systemctl reload snap.lxd.daemon systemctl status snap.lxd.daemon |
troubleshoot network sudo tcpdump -i eth0 -vn icmp sudo nmcli c up System\ eth0 ps uax | grep systemd-udev ps aux | grep dnsmasq ip addr flush ip addr show ip a ip r |
sudo snap install lxd sudo snap install lxd --channel=3.0/stable sudo snap install lxd --channel=4.0/stable sudo snap install lxd --channel=5.0/stable sudo groupadd --system lxd sudo usermod -G lxd -a $USER newgrp lxd mount | grep cgroup systemd.unified_cgroup_hierarchy=0 cat /var/snap/lxd/common/lxd/logs/lxd.log |
| ||
sudo apt update && sudo apt list --upgradable sudo apt upgrade && sudo apt autoremove sudo apt install snapd sudo zfs list -t all sudo ps fauxww sudo lxd.migrate sudo lxd init --auto sudo lxd init lxc remote list lxc image list |
lxc image list images: lxc image list images: alpine lxc image list images: alpine arm64 lxc image list images: alpine amd64 lxc image list images: debian lxc image list images: debian arm64 lxc image list images: debian amd64 lxc image list images: oracle lxc image list images: oracle arm64 lxc image list images: oracle amd64 |
lxc image list images: ubuntu lxc image list images: ubuntu arm64 lxc image list images: ubuntu amd64 sudo ls -la /var/snap/lxd/common/lxd/images/ sudo cat /var/snap/lxd/common/lxcfs.pid sudo systemctl stop snap.lxd.daemon sudo apt install zfsutils-linux sudo lxc --verbose --debug list sudo lxd --debug --group lxd sudo ps fauxww | grep lx |
| ||
lxc launch images:alpine/3.17 academia lxc snapshot academia install:curl lxc snapshot academia install:java lxc info academia |
lxc launch images:opensuse/15.3 agronomy lxc snapshot agronomy install:curl lxc snapshot agronomy install:java lxc info agronomy |
lxc launch images:ubuntu/22.04 software lxc snapshot agronomy install:curl lxc snapshot agronomy install:java lxc info software |