Lxc: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
==Create container== | ==Create container== | ||
< | <syntaxhighlight lang=bash> | ||
drew@drew-itx:~$ sudo lxc-create -n test-container -t ubuntu | |||
Checking cache download in /var/cache/lxc/trusty/rootfs-amd64 ... | Checking cache download in /var/cache/lxc/trusty/rootfs-amd64 ... | ||
Installing packages in template: ssh,vim,language-pack-en | Installing packages in template: ssh,vim,language-pack-en | ||
Line 13: | Line 14: | ||
I: Validating Packages | I: Validating Packages | ||
I: Resolving dependencies of required packages... | I: Resolving dependencies of required packages... | ||
I: Resolving dependencies of base packages...</ | I: Resolving dependencies of base packages... | ||
</syntaxhighlight> | |||
==Show containers status== | ==Show containers status== | ||
< | <syntaxhighlight lang=bash> | ||
# lxc-ls --fancy | |||
</syntaxhighlight> | |||
==Start Container w/ Console== | ==Start Container w/ Console== | ||
< | <syntaxhighlight lang=bash> | ||
# lxc-start -n test-container -d | |||
</syntaxhighlight> | |||
==Connect to console== | ==Connect to console== | ||
< | <syntaxhighlight lang=bash> | ||
# lxc-console -n test-container | |||
</syntaxhighlight> | |||
Exit by typing Ctrl-A followed by Q | Exit by typing Ctrl-A followed by Q | ||
==shutdown (lxc-stop for instant shutdown)== | ==shutdown (lxc-stop for instant shutdown)== | ||
< | <syntaxhighlight lang=bash> | ||
# lxc-shutdown -n test-container | |||
</syntaxhighlight> | |||
==delete== | ==delete== | ||
< | <syntaxhighlight lang=bash> | ||
lxc-destroy -n test-container | |||
</syntaxhighlight> | |||
==Configuration== | ==Configuration== | ||
Line 36: | Line 48: | ||
to auto start | to auto start | ||
<syntaxhighlight lang=bash> | |||
ln -s /var/lib/lxc/test-container/config /etc/lxc/auto/test-container.conf | ln -s /var/lib/lxc/test-container/config /etc/lxc/auto/test-container.conf | ||
</syntaxhighlight> | |||
==Port forward to container== | ==Port forward to container== | ||
<syntaxhighlight lang=bash> | |||
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 10022 -j DNAT --to-destination 10.0.3.239:22 | $ iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 10.0.3.143:80 | ||
$ iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 10022 -j DNAT --to-destination 10.0.3.239:22 | |||
</syntaxhighlight> |
Latest revision as of 01:05, 25 January 2018
Create container
drew@drew-itx:~$ sudo lxc-create -n test-container -t ubuntu
Checking cache download in /var/cache/lxc/trusty/rootfs-amd64 ...
Installing packages in template: ssh,vim,language-pack-en
Downloading ubuntu trusty minimal ...
I: Retrieving Release
I: Retrieving Release.gpg
I: Checking Release signature
I: Valid Release signature (key id 790BC7277767219C42C86F933B4FE6ACC0B21F32)
I: Retrieving Packages
I: Validating Packages
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
Show containers status
# lxc-ls --fancy
Start Container w/ Console
# lxc-start -n test-container -d
Connect to console
# lxc-console -n test-container
Exit by typing Ctrl-A followed by Q
shutdown (lxc-stop for instant shutdown)
# lxc-shutdown -n test-container
delete
lxc-destroy -n test-container
Configuration
config is /var/lib/lxc/test-container/config
to auto start
ln -s /var/lib/lxc/test-container/config /etc/lxc/auto/test-container.conf
Port forward to container
$ iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 10.0.3.143:80
$ iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 10022 -j DNAT --to-destination 10.0.3.239:22