-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlxd-lxc.txt
More file actions
136 lines (92 loc) · 3.73 KB
/
Copy pathlxd-lxc.txt
File metadata and controls
136 lines (92 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#Installing LXD/LXC on ubuntu
apt install lxd lxd-client
#Intialize LXD for configuration, use defaults by just pressing enter multiple times
#If you want containers to run on ZFS, first install zfsutils-linux before init
lxd init
#Show a list of containers
lxc list
#Create a new ubuntu 18.04 container, container name optional
lxc launch ubuntu:18.04 <container name>
#Create a new CentOS 8 container from the image store
lxc launch images:centos/8 <container name>
#Open bash shell in container
lxc exec <container name> -- /bin/bash
#To stop running container
lxc stop <container name>
#To delete container, must be stopped
lxc rm <container name>
#To start a stoppped container
lxc start <container name>
#Lauch local file editor of a file on a container
lxc file edit <container name>/filepath/filename
#Push a local file to container
lxc file push <filename> <container name>/filepath
#Create snapshot of container
lxc snapshot <container name> <snapshot name>
#To view details about container
lxc info <container name>
#To restore container from previous snapshot
lxc restore <container name> <snapshot name>
#To delete a snapshot
lxc delect <container>/<snapshot name>
#To create a new container from other container's snapshot
lxc copy <old container name>/<snapshot> <new container name>
-------------------------------------------------------
#Show network profiles
lxc profile list
#See details of profile
lxc profile show <profile name>
#Copy default network profile to new profile
lxc profile copy default <new profile>
#Edit profile using editor
lxc profile edit <profile name>
#Create container that uses a specific profile
lxc launch -p <profile name> ubuntu:18.04 <container name>
#Example of macvlan interface
eth1:
name: eth1
nictype: macvlan
parent: eno1
type: nic
-------------------------------------------------------
#List of remote locations to download images from
lxc remote list
#List downloaded container images
lxc image list
#To delete locally saved images
lxc image delete <image name>
#Working with lightweight alpine container
- lxc launch images:alpine/3.5 alpine-matt #gets from remote location
- lxc exec alpine-matt --ash #does not have /bin/bash, very light linux
#Troubleshooting issues
- Missing parent lxdbr0 error
- sudo dpkg-reconfigure -p medium lxd
-------------------------------------------------------
#Setup remote port listening for secondary server
lxc config set core.https_address "[::]:8443"
#Setup password for lxc connections
lxc config set core.trust_password <password>
#Connect to remote lxc server
lxc remote add <label> <ip address>:8443
#List running containers on remote server
lxc list <label>
#List images on remote server
lxc image list second
-------------------------------------------------------
#Publish snapshot to a useable image
lxc publish <container>/<snapshot> --alias <new image name>
#Export a container, outputs to a .tar.gz file
lxc image export <image> <filepath>
#Import a container on a new host server
lxc image import <tar file> --alias <image name>
-------------------------------------------------------
#Forwarding of traffic can be used to direct host network traffic to container
#Check to see if forwarding is turned on, should come back as 1 not 0 for forwarding
systemctl net.ipv4.ip_forward
#Using IPTABLES to forward host tcp port 80 to container with ip 10.10.10.120
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to 10.10.10.120:80
-------------------------------------------------------
#Change security to run docker within lxc/lxd containers
lxc config set <container> security.nesting true
#Change security to allow lxc/lxd containers to mount nfs/smb shares
lxc config set <container> security.privileged true