Compare commits
13 Commits
818f22679d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6aeb5ca655 | |||
| 20ff1390dd | |||
| 7d2beca0ca | |||
| 0dbb1ed83f | |||
| 6b93bc4400 | |||
| 6a2e10ea7b | |||
| f8ee7d79d6 | |||
| 576c4d411f | |||
| ebe48d2e4e | |||
| d00bbb38ea | |||
| 8928cfb4f6 | |||
| 6c9a27fe67 | |||
| a7283e9280 |
126
README.md
126
README.md
@@ -1,2 +1,128 @@
|
|||||||
# lxc
|
# lxc
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
requires snap
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt install snap
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo snap install lxd
|
||||||
|
sudo usermod -a -G lxd $(whoami)
|
||||||
|
```
|
||||||
|
|
||||||
|
Init
|
||||||
|
|
||||||
|
Setup lxd
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo lxd init
|
||||||
|
```
|
||||||
|
|
||||||
|
## Containers
|
||||||
|
|
||||||
|
### List
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc list
|
||||||
|
```
|
||||||
|
|
||||||
|
### Get Info
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc info containername
|
||||||
|
```
|
||||||
|
|
||||||
|
### Create
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc launch ubuntu containername
|
||||||
|
```
|
||||||
|
|
||||||
|
### move
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc mv ubuntu ubuntu1
|
||||||
|
lxc mv ubuntu1 -s=poolname
|
||||||
|
```
|
||||||
|
|
||||||
|
### Stop
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc stop containername
|
||||||
|
```
|
||||||
|
|
||||||
|
Exec bash on container
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc exec $containername bash
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exec multiple commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc exec "container name" -- bash -c "apt update -y && apt upgrade -y"
|
||||||
|
```
|
||||||
|
|
||||||
|
### delete a container
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc rm "container name"
|
||||||
|
#if force required
|
||||||
|
lxc rm "container name" --force
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
Edit
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc config edit "container name"
|
||||||
|
```
|
||||||
|
|
||||||
|
Set value
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#Example
|
||||||
|
lxc config set "container name" "security.nesting" "true"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Profile Management
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc profile remove "container name" "profile name to remote"
|
||||||
|
lxc profile assign "container name" "profile name to assign"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Profiles
|
||||||
|
|
||||||
|
### macvlan only
|
||||||
|
|
||||||
|
1) create copy from default
|
||||||
|
|
||||||
|
```bash
|
||||||
|
lxc profile copy default eth0_macvlan
|
||||||
|
lxc profile edit eth0_macvlan
|
||||||
|
```
|
||||||
|
|
||||||
|
1) edit new profile
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
devices:
|
||||||
|
eth0:
|
||||||
|
nictype: macvlan
|
||||||
|
parent: eth0 # parent ethernet name
|
||||||
|
type: nic
|
||||||
|
```
|
||||||
|
|
||||||
|
## swap
|
||||||
|
|
||||||
|
swap on lxc
|
||||||
|
limits.memory.swap: "false"
|
||||||
|
|
||||||
|
swap on host
|
||||||
|
https://www.shellhacks.com/swappiness-in-linux-ubuntu-how-to-change/
|
||||||
|
|||||||
@@ -9,15 +9,10 @@ on a lxc container
|
|||||||
- security.nesting: "true"
|
- security.nesting: "true"
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc config edit ${CONTAINER_NAME}
|
lxc config set $CONTAINER_NAME "security.nesting" "true"
|
||||||
|
#/scripts/lxc-config-docker-requirements.sh $CONTAINER_NAME
|
||||||
```
|
```
|
||||||
|
|
||||||
### setup ubuntu container
|
### setup ubuntu container
|
||||||
|
|
||||||
```bash
|
Install docker with fuse fs [more information] (/kb/docker)
|
||||||
apt-get install --yes fuse-overlayfs
|
|
||||||
cd ~/
|
|
||||||
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
|
|
||||||
docker run hello-world
|
|
||||||
docker info
|
|
||||||
```
|
|
||||||
|
|||||||
2
scripts/lxc-config-docker-requirements.sh
Normal file
2
scripts/lxc-config-docker-requirements.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
lxc config set $1 "security.nesting" "true"
|
||||||
22
templates/lxc-portainer.sh
Normal file
22
templates/lxc-portainer.sh
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
LXC_CONTAINER_NAME=$1
|
||||||
|
LXC_PROFILE=$2
|
||||||
|
|
||||||
|
echo "container name: $LXC_CONTAINER_NAME"
|
||||||
|
echo "profile: $LXC_PROFILE"
|
||||||
|
|
||||||
|
echo "starting container"
|
||||||
|
lxc launch ubuntu $LXC_CONTAINER_NAME -p $LXC_PROFILE
|
||||||
|
|
||||||
|
echo "setting lxc docker requirements"
|
||||||
|
curl -s "https://git.limbosolutions.com/kb/lxc/raw/branch/main/scripts/lxc-config-docker-requirements.sh" | bash -s $LXC_CONTAINER_NAME
|
||||||
|
lxc restart $LXC_CONTAINER_NAME
|
||||||
|
echo "updating apt"
|
||||||
|
lxc exec $LXC_CONTAINER_NAME -- sh -c "apt-get update -qq >/dev/null"
|
||||||
|
echo "upgrading apt"
|
||||||
|
lxc exec $LXC_CONTAINER_NAME -- sh -c "apt-get upgrade -qq >/dev/null"
|
||||||
|
echo "installing fuse & docker"
|
||||||
|
lxc exec $LXC_CONTAINER_NAME -- bash -c "curl -s \"https://git.limbosolutions.com/kb/docker/raw/branch/main/scripts/ubuntu-fuse-setup.sh\" | bash"
|
||||||
|
echo "installing portainer"
|
||||||
|
lxc exec $LXC_CONTAINER_NAME -- bash -c "curl -s \"https://git.limbosolutions.com/kb/portainer/raw/branch/main/scripts/setup.sh\" | bash"
|
||||||
Reference in New Issue
Block a user