Compare commits
3 Commits
0dbb1ed83f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6aeb5ca655 | |||
| 20ff1390dd | |||
| 7d2beca0ca |
248
README.md
248
README.md
@@ -1,120 +1,128 @@
|
|||||||
# lxc
|
# lxc
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
requires snap
|
requires snap
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo apt install snap
|
sudo apt install snap
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo snap install lxd
|
sudo snap install lxd
|
||||||
sudo usermod -a -G lxd $(whoami)
|
sudo usermod -a -G lxd $(whoami)
|
||||||
```
|
```
|
||||||
|
|
||||||
Init
|
Init
|
||||||
|
|
||||||
Setup lxd
|
Setup lxd
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo lxd init
|
sudo lxd init
|
||||||
```
|
```
|
||||||
|
|
||||||
## Containers
|
## Containers
|
||||||
|
|
||||||
### List
|
### List
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc list
|
lxc list
|
||||||
```
|
```
|
||||||
|
|
||||||
### Get Info
|
### Get Info
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc info containername
|
lxc info containername
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create
|
### Create
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc launch ubuntu containername
|
lxc launch ubuntu containername
|
||||||
```
|
```
|
||||||
|
|
||||||
### move
|
### move
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc mv ubuntu ubuntu1
|
lxc mv ubuntu ubuntu1
|
||||||
lxc mv ubuntu1 -s=poolname
|
lxc mv ubuntu1 -s=poolname
|
||||||
```
|
```
|
||||||
|
|
||||||
### Stop
|
### Stop
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc stop containername
|
lxc stop containername
|
||||||
```
|
```
|
||||||
|
|
||||||
Exec bash on container
|
Exec bash on container
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc exec $containername bash
|
lxc exec $containername bash
|
||||||
```
|
```
|
||||||
|
|
||||||
### Exec multiple commands
|
### Exec multiple commands
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc exec "container name" -- bash -c "apt update -y && apt upgrade -y"
|
lxc exec "container name" -- bash -c "apt update -y && apt upgrade -y"
|
||||||
```
|
```
|
||||||
|
|
||||||
### delete a container
|
### delete a container
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc rm "container name"
|
lxc rm "container name"
|
||||||
#if force required
|
#if force required
|
||||||
lxc rm "container name" --force
|
lxc rm "container name" --force
|
||||||
```
|
```
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
Edit
|
Edit
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc config edit "container name"
|
lxc config edit "container name"
|
||||||
```
|
```
|
||||||
|
|
||||||
Set value
|
Set value
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
#Example
|
#Example
|
||||||
lxc config set "container name" "security.nesting" "true"
|
lxc config set "container name" "security.nesting" "true"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Profile Management
|
### Profile Management
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc profile remove "container name" "profile name to remote"
|
lxc profile remove "container name" "profile name to remote"
|
||||||
lxc profile assign "container name" "profile name to assign"
|
lxc profile assign "container name" "profile name to assign"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Profiles
|
## Profiles
|
||||||
|
|
||||||
### macvlan only
|
### macvlan only
|
||||||
|
|
||||||
1) create copy from default
|
1) create copy from default
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc profile copy default eth0_macvlan
|
lxc profile copy default eth0_macvlan
|
||||||
lxc profile edit eth0_macvlan
|
lxc profile edit eth0_macvlan
|
||||||
```
|
```
|
||||||
|
|
||||||
1) edit new profile
|
1) edit new profile
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
||||||
devices:
|
devices:
|
||||||
eth0:
|
eth0:
|
||||||
nictype: macvlan
|
nictype: macvlan
|
||||||
parent: eth0 # parent ethernet name
|
parent: eth0 # parent ethernet name
|
||||||
type: nic
|
type: nic
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## swap
|
||||||
|
|
||||||
|
swap on lxc
|
||||||
|
limits.memory.swap: "false"
|
||||||
|
|
||||||
|
swap on host
|
||||||
|
https://www.shellhacks.com/swappiness-in-linux-ubuntu-how-to-change/
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
# Running Docker
|
# Running Docker
|
||||||
|
|
||||||
on a lxc container
|
on a lxc container
|
||||||
|
|
||||||
## setup lxc container for docker
|
## setup lxc container for docker
|
||||||
|
|
||||||
### Config
|
### Config
|
||||||
|
|
||||||
- security.nesting: "true"
|
- security.nesting: "true"
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lxc config set $CONTAINER_NAME "security.nesting" "true"
|
lxc config set $CONTAINER_NAME "security.nesting" "true"
|
||||||
#/scripts/lxc-config-docker-requirements.sh $CONTAINER_NAME
|
#/scripts/lxc-config-docker-requirements.sh $CONTAINER_NAME
|
||||||
```
|
```
|
||||||
|
|
||||||
### setup ubuntu container
|
### setup ubuntu container
|
||||||
|
|
||||||
Install docker with fuse fs [more information] (/kb/docker)
|
Install docker with fuse fs [more information] (/kb/docker)
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#start container
|
|
||||||
echo "$1"
|
|
||||||
echo "$2"
|
|
||||||
#lxc launch ubuntu $1 -p $2
|
|
||||||
|
|
||||||
#set docker requirements
|
LXC_CONTAINER_NAME=$1
|
||||||
curl -s "https://git.limbosolutions.com/kb/lxc/raw/branch/main/scripts/lxc-config-docker-requirements.sh" | bash -s $1
|
LXC_PROFILE=$2
|
||||||
lxc restart $1
|
|
||||||
lxc exec $1 -- bash -c "apt update -y && apt upgrade -y"
|
|
||||||
|
|
||||||
#setup docker
|
echo "container name: $LXC_CONTAINER_NAME"
|
||||||
lxc exec $1 -- bash -c "curl -s \"https://git.limbosolutions.com/kb/docker/raw/branch/main/scripts/ubuntu-fuse-setup.sh\" | bash"
|
echo "profile: $LXC_PROFILE"
|
||||||
|
|
||||||
#portainer
|
echo "starting container"
|
||||||
lxc exec $1 -- bash -c "curl -s \"https://git.limbosolutions.com/kb/portainer/raw/branch/main/scripts/setup.sh\" | bash"
|
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