Documentation interne
From LXC to docker container
-
Minimum prerequisites :
-
Access to the rootfs folder of the LXC of interest.
-
Docker somewhere.Â
In a nutshell
On Proxmox, mount the CT volume:
pct mount {id} |
Import the rootfs folder as a docker image:
tar -C /var/lib/lxc/{id}/rootfs -c . | docker import - {imagename:tagname} |
Create a container from the image:
docker run -d âname {containername} -p 8000:80 {imagename:tagname} tail -f /dev/null |
With Proxmox and Docker on two different hostsÂ
In a shell
On the Proxmox host, mount the LXC and extract its rootfs:
pct mount {id} cp -rp /var/lib/lxc/{id}/rootfs /tmp/rootfs pct unmount {id} |
Archive the copied rootfs folder then delete it:
tar -czvf rootfs.tar.gz /tmp/rootfs rm -r /tmp/rootfs |
Scp it to the docker server:
scp rootfs.tar.gz {docker-user}@{docker-server}:/home/{docker-user}/ rm /tmp/rootfs.tar.gz |
On the Docker host, untar the archive:
tar -xzf rootfs.tar.gz rm rootfs.tar.gz |
Then import the rootfs folder as a docker image:
tar -C ./rootfs -c . | sudo docker import - {imagename:tagname} rm -r rootfs |
You can now create a container from the image:
docker run -d âname {containername} -p 8000:80 {imagename:tagname} tail -f /dev/null |
In an Ansible playbookÂ
Donât forget to adapt this playbook to your needs.
- name: Transfer rootfs from Proxmox to Docker server   hosts: proxmox   tasks: - name: Mount container volume   shell: pct mount {id} - name: Copy rootfs to temporary directory   shell: cp -rp /var/lib/lxc/{id}/rootfs /tmp/rootfs - name: Unmount container volume   shell: pct unmount {id} - name: Create tar.gz archive   shell: tar -czvf rootfs.tar.gz -C /tmp/ rootfs/   args:     chdir: /tmp - name: Transfer archive to Docker server   shell: scp /tmp/rootfs.tar.gz {docker-user}@{docker-server}:/home/{docker-user}/ - name: Remove temporary files   file:     path: /tmp/rootfs.tar.gz     state: absent   register: remove_tmp_files - name: Import rootfs as Docker image and run container   hosts: docker_server   tasks: - name: Untar archive   unarchive:     src: /home/{docker-user}/rootfs.tar.gz     dest: /home/{docker-user}     remote_src: yes - name: Import rootfs folder as Docker image   shell: tar -C /home/{docker-user}/rootfs -c . | sudo docker import - {imagename:tagname} - name: Delete extracted archive   shell: rm -r /home/{docker-user}/rootfs |
Updating your image from the docker container
Say you made changes from within your docker container, and would like to push those changes to your local image.Â
First, commit the changes you made to the container to a new image.
docker commit {containername} Â {new_imagename} |
Then tag the new image with the same name as the existing image so that it replaces the old one.
docker tag {new_imagename} {imagename:tagname}:latest |
Optionally, you can remove the old image to avoid confusion.Â
docker rmi {imagename:tagname} |
Note: Watchtower can do this automatically and more gracefully, but I havenât looked into it yet.
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto vmbr0
iface vmbr0 inet static
address 10.10.10.1/24
bridge-ports none
bridge-stp off
bridge-fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o eno1 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o eno1 -j MASQUERADE
post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1
post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1
post-up iptables -t nat -A PREROUTING -p tcp --dport 22 -i eno1 -d 192.168.3.111 -m conntrack --ctstate NEW -j DNAT --to 10.10.10.11:22
post-down iptables -t nat -D PREROUTING -p tcp --dport 22 -i eno1 -d 192.168.3.111 -m conntrack --ctstate NEW -j DNAT --to 10.10.10.11:22
source /etc/network/interfaces.d/*
root@tools:/tmp# ip route
default via 192.168.2.1 dev eno1
10.10.10.0/24 dev vmbr0 proto kernel scope link src 10.10.10.1
192.168.2.0/23 dev eno1 proto kernel scope link src 192.168.3.111
dâabord tu me rassemble les points abordĂ©s dans une doc comme je tâai demandĂ© stp
ensuite tu me mets les Ă©tapes de ton plan dâaction pour faire tes tests avec LXC
Env sur windows â non
Tech de container â LXC (plus simple Ă comprendre que Docker)
RĂ©seau interne et local â Bridges Linux (bridge-utils) et iptables.
lxc vs docker, les plus et les moins
Prend ce /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto vmbr0
iface vmbr0 inet static
address 10.10.10.1/24
bridge-ports none
bridge-stp off
bridge-fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o eno1 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o eno1 -j MASQUERADE
post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1
post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1
source /etc/network/interfaces.d/*
-
Lâinterface physique âeth0â est en dhcp, câest lâinterface qui fait face au reste du monde.
-
Vmbr0 est un bridge linux. Câest une interface virtuel qui fera office de gateway pour le sous-rĂ©seau interne et virtuel â10.10.10.0/24â.
bridge-ports none
Signifie que le bridge ne gĂšre pas directement une interface physique.
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
Active le routage.
post-up iptables -t nat -A POSTROUTING -s â10.10.10.0/24â -o eno1 -j MASQUERADE
NAT et rend anonyme les communications sortantes du LAN de vmbr0.
post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT âzone 1
Ceci est du debug pour proxmox. Je ne sais pas si ça sera nĂ©cessaire pour un desktop, faut tester. En soit pas obligatoire.Et pouf, tâa un LAN dans ton PC. Le bridge sera utilisĂ© pour les interfaces virtuelles au sein de lâhĂŽte lui-mĂȘme. En gros, pour les VMs et les LXC. (modifiĂ©)Â
La table de routage ressemblera à quelque chose comme ça :
root@tools:/tmp# ip route default via 192.168.2.1 dev eth0 10.10.10.0/24 dev vmbr0 proto kernel scope link src 10.10.10.1 192.168.2.0/23 dev eth0 proto kernel scope link src 192.168.3.111
auto-creation of popular services
auto-creation of html pages into dooku-wiki (say, for backup jobs)
template for docs?
Find something markdown. Can dookuwiki do markdown?
-
Les commandes pour créer un LXC. Ok.
-
Les commandes pour gérer un LXC. Ok. IP ?
-
Les configurations requises pour exécuter les LXC en nesting et unpriviliged. Ok pour unpriviliged. Nesting ?
-
Les commandes pour backup un LXC. Snapshot existe.
Ok donc, comment transcrire ça avec LXC tout court ?
Des fichiers confs individuels existent. Mais la syntaxe est différente.
think to reinstall busybox on that machine!
[connection]
id=vmbr0
uuid=12345678-1234-1234-1234-1234567890ab
type=bridge
autoconnect-priority=-999
[bridge]
interface-name=vmbr0
stp=false
forward-delay=0
[ipv4]
method=manual
address1=10.10.10.1/24
gateway=0.0.0.0
dns=0.0.0.0;
[ipv6]
method=ignore
[proxy]
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o eno1 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o eno1 -j MASQUERADE
post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1
post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1