Demo/docker #18
No files matched your search
+113
-9
@@ -201,9 +201,10 @@ exit # back to the ho
|
|||||||
|
|
||||||
## Going further
|
## Going further
|
||||||
|
|
||||||
- **Reach the service from the host.** Port 8080 is published by Docker inside
|
### Reach the service from the host
|
||||||
the instance. An LXD `proxy` device makes it reachable on the host (and so
|
|
||||||
from your network):
|
Port 8080 is published by Docker inside the instance. An LXD `proxy` device
|
||||||
|
makes it reachable on the host (and so from your network):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
lxc config device add docker web proxy listen=tcp:0.0.0.0:8080 connect=tcp:127.0.0.1:8080
|
lxc config device add docker web proxy listen=tcp:0.0.0.0:8080 connect=tcp:127.0.0.1:8080
|
||||||
@@ -213,19 +214,122 @@ exit # back to the ho
|
|||||||
If port 8080 is already taken on the host, change the `listen` one. The
|
If port 8080 is already taken on the host, change the `listen` one. The
|
||||||
repository also has ready-made profiles for that (`proxy-http`,
|
repository also has ready-made profiles for that (`proxy-http`,
|
||||||
`proxy-https`).
|
`proxy-https`).
|
||||||
- **Combine profiles.** Profiles stack at launch: instance size
|
|
||||||
(`size-small`, `size-medium`…), automatic snapshots (`snapshots-daily`), a
|
### Keep Docker data in a volume, with automatic snapshots
|
||||||
dedicated volume for Docker data (`docker-volume-data`)…
|
|
||||||
|
By default, Docker images, containers and volumes live in `/var/lib/docker`,
|
||||||
|
on the instance disk: they go away with it. The `docker-volume-data` profile
|
||||||
|
mounts a dedicated LXD volume there instead, with a life of its own: it
|
||||||
|
survives the instance deletion, attaches to a new one, and is backed up
|
||||||
|
separately.
|
||||||
|
|
||||||
|
The volume must exist **before** the profile is installed, LXD checks it.
|
||||||
|
Create it on the `default` pool, the one the profile expects, and schedule
|
||||||
|
snapshots for it: one a day, kept for two weeks.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
lxc storage volume create default docker-data size=20GiB
|
||||||
|
lxc storage volume set default docker-data snapshots.schedule=@daily snapshots.expiry=2w
|
||||||
|
mise run install docker-volume-data
|
||||||
|
```
|
||||||
|
|
||||||
|
Add the profile **when the instance is created**, so that Docker installs
|
||||||
|
directly on the volume:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
lxc launch ubuntu:lts docker --profile default --profile docker-unprivileged --profile docker-volume-data
|
||||||
|
lxc exec docker -- findmnt --target /var/lib/docker # the volume is mounted
|
||||||
|
```
|
||||||
|
|
||||||
|
Volume snapshots are handled with `lxc storage volume`:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
lxc storage volume snapshot default docker-data before-upgrade # manual snapshot
|
||||||
|
lxc storage volume info default docker-data # list of snapshots
|
||||||
|
lxc stop docker # instance stopped to restore
|
||||||
|
lxc storage volume restore default docker-data before-upgrade
|
||||||
|
lxc start docker
|
||||||
|
```
|
||||||
|
|
||||||
|
The `snapshots-daily` profile is not enough here: it schedules snapshots of
|
||||||
|
the **instance**, which do not include attached volumes. These are two
|
||||||
|
separate settings, and both can be combined.
|
||||||
|
|
||||||
|
### Adapt an installed profile to your needs
|
||||||
|
|
||||||
|
The repository profiles are a starting point. Say you want Docker data on
|
||||||
|
another, faster pool named `fast`. Copy the volume (with its snapshots and
|
||||||
|
their schedule), then change the profile installed in LXD directly:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
lxc stop docker
|
||||||
|
lxc storage volume copy default/docker-data fast/docker-data
|
||||||
|
lxc profile device set docker-volume-data docker-data pool=fast
|
||||||
|
lxc start docker
|
||||||
|
lxc storage volume delete default docker-data # once checked
|
||||||
|
```
|
||||||
|
|
||||||
|
The volume is **copied** rather than moved: LXD refuses to move a volume a
|
||||||
|
profile refers to. The change applies to every instance using the profile.
|
||||||
|
|
||||||
|
The installed profile no longer matches the repository, and the mise tasks
|
||||||
|
say so:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mise run list | grep docker-volume-data # 📝: installed but different
|
||||||
|
mise run diff docker-volume-data
|
||||||
|
```
|
||||||
|
|
||||||
|
```diff
|
||||||
|
--- lxd:docker-volume-data (installé)
|
||||||
|
+++ profiles/containerization/docker-volume-data.profile.yaml (dépôt)
|
||||||
|
@@ -3,7 +3,7 @@
|
||||||
|
devices:
|
||||||
|
docker-data:
|
||||||
|
path: /var/lib/docker
|
||||||
|
- pool: fast
|
||||||
|
+ pool: default
|
||||||
|
source: docker-data
|
||||||
|
type: disk
|
||||||
|
```
|
||||||
|
|
||||||
|
Two options then:
|
||||||
|
|
||||||
|
- **back to the repository version**: `mise run install docker-volume-data`
|
||||||
|
shows this diff and asks for confirmation before overwriting the profile;
|
||||||
|
- **keep your version**: `mise run import docker-volume-data` rewrites the
|
||||||
|
repository file from the installed profile. Review it with `git diff`, then
|
||||||
|
commit it in your clone (or your fork).
|
||||||
|
|
||||||
|
A volume can only be attached to one instance at a time. For a second Docker
|
||||||
|
instance, copy the profile and give it its own volume:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
lxc storage volume create default docker2-data
|
||||||
|
lxc profile copy docker-volume-data docker2-volume-data
|
||||||
|
lxc profile device set docker2-volume-data docker-data source=docker2-data
|
||||||
|
```
|
||||||
|
|
||||||
|
### Combine profiles
|
||||||
|
|
||||||
|
Profiles stack at launch: instance size (`size-small`, `size-medium`…),
|
||||||
|
automatic instance snapshots (`snapshots-daily`), data volume
|
||||||
|
(`docker-volume-data`)…
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
lxc launch ubuntu:lts docker --profile default --profile docker-unprivileged \
|
lxc launch ubuntu:lts docker --profile default --profile docker-unprivileged \
|
||||||
--profile size-medium --profile snapshots-daily
|
--profile docker-volume-data --profile size-medium --profile snapshots-daily
|
||||||
```
|
```
|
||||||
- **Clean up.** The instance goes away with one command, Docker and its images
|
|
||||||
with it; the profile too, if no longer needed:
|
### Clean up
|
||||||
|
|
||||||
|
The instance goes away with one command, Docker with it. The data volume
|
||||||
|
stays: delete it explicitly if no longer needed, like the profiles.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
lxc delete --force docker
|
lxc delete --force docker
|
||||||
|
lxc storage volume delete default docker-data
|
||||||
|
lxc profile delete docker-volume-data
|
||||||
lxc profile delete docker-unprivileged
|
lxc profile delete docker-unprivileged
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+115
-9
@@ -201,9 +201,10 @@ exit # retour sur l'h
|
|||||||
|
|
||||||
## Pour aller plus loin
|
## Pour aller plus loin
|
||||||
|
|
||||||
- **Accéder au service depuis l'hôte.** Le port 8080 publié par Docker l'est
|
### Accéder au service depuis l'hôte
|
||||||
dans l'instance. Un device `proxy` LXD le rend joignable sur l'hôte (et donc
|
|
||||||
depuis votre réseau) :
|
Le port 8080 publié par Docker l'est dans l'instance. Un device `proxy` LXD le
|
||||||
|
rend joignable sur l'hôte (et donc depuis votre réseau) :
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
lxc config device add docker web proxy listen=tcp:0.0.0.0:8080 connect=tcp:127.0.0.1:8080
|
lxc config device add docker web proxy listen=tcp:0.0.0.0:8080 connect=tcp:127.0.0.1:8080
|
||||||
@@ -213,19 +214,124 @@ exit # retour sur l'h
|
|||||||
Si le port 8080 est déjà pris sur l'hôte, changez celui de `listen`. Le dépôt
|
Si le port 8080 est déjà pris sur l'hôte, changez celui de `listen`. Le dépôt
|
||||||
propose aussi des profils prêts à l'emploi pour ça (`proxy-http`,
|
propose aussi des profils prêts à l'emploi pour ça (`proxy-http`,
|
||||||
`proxy-https`).
|
`proxy-https`).
|
||||||
- **Combiner les profils.** Les profils s'empilent au lancement : taille de
|
|
||||||
l'instance (`size-small`, `size-medium`…), snapshots automatiques
|
### Garder les données Docker dans un volume, avec des snapshots automatiques
|
||||||
(`snapshots-daily`), volume dédié aux données Docker (`docker-volume-data`)…
|
|
||||||
|
Par défaut, images, conteneurs et volumes Docker vivent dans `/var/lib/docker`,
|
||||||
|
sur le disque de l'instance : ils disparaissent avec elle. Le profil
|
||||||
|
`docker-volume-data` y monte plutôt un volume LXD dédié, qui a sa propre vie :
|
||||||
|
il survit à la suppression de l'instance, se rattache à une nouvelle, et se
|
||||||
|
sauvegarde à part.
|
||||||
|
|
||||||
|
Le volume doit exister **avant** l'installation du profil, LXD le vérifie. On
|
||||||
|
le crée sur le pool `default`, celui qu'attend le profil, et on lui programme
|
||||||
|
des snapshots : un par jour, gardé deux semaines.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
lxc storage volume create default docker-data size=20GiB
|
||||||
|
lxc storage volume set default docker-data snapshots.schedule=@daily snapshots.expiry=2w
|
||||||
|
mise run install docker-volume-data
|
||||||
|
```
|
||||||
|
|
||||||
|
Le profil s'ajoute **à la création** de l'instance, pour que Docker s'installe
|
||||||
|
directement sur le volume :
|
||||||
|
|
||||||
|
```shell
|
||||||
|
lxc launch ubuntu:lts docker --profile default --profile docker-unprivileged --profile docker-volume-data
|
||||||
|
lxc exec docker -- findmnt --target /var/lib/docker # le volume est bien monté
|
||||||
|
```
|
||||||
|
|
||||||
|
Les snapshots du volume se gèrent avec `lxc storage volume` :
|
||||||
|
|
||||||
|
```shell
|
||||||
|
lxc storage volume snapshot default docker-data avant-maj # snapshot manuel
|
||||||
|
lxc storage volume info default docker-data # liste des snapshots
|
||||||
|
lxc stop docker # instance arrêtée pour restaurer
|
||||||
|
lxc storage volume restore default docker-data avant-maj
|
||||||
|
lxc start docker
|
||||||
|
```
|
||||||
|
|
||||||
|
Le profil `snapshots-daily` ne suffit pas ici : il programme les snapshots de
|
||||||
|
l'**instance**, qui n'incluent pas les volumes attachés. Ce sont deux réglages
|
||||||
|
distincts, et on peut combiner les deux.
|
||||||
|
|
||||||
|
### Adapter un profil installé à son besoin
|
||||||
|
|
||||||
|
Les profils du dépôt sont un point de départ. Imaginons que vous vouliez les
|
||||||
|
données Docker sur un autre pool, plus rapide, nommé `fast`. Le volume se copie
|
||||||
|
(avec ses snapshots et leur programmation), puis on modifie directement le
|
||||||
|
profil installé dans LXD :
|
||||||
|
|
||||||
|
```shell
|
||||||
|
lxc stop docker
|
||||||
|
lxc storage volume copy default/docker-data fast/docker-data
|
||||||
|
lxc profile device set docker-volume-data docker-data pool=fast
|
||||||
|
lxc start docker
|
||||||
|
lxc storage volume delete default docker-data # une fois vérifié
|
||||||
|
```
|
||||||
|
|
||||||
|
Le volume se **copie** plutôt qu'il ne se déplace : LXD refuse de déplacer un
|
||||||
|
volume auquel un profil fait référence. La modification s'applique à toutes les
|
||||||
|
instances qui utilisent le profil.
|
||||||
|
|
||||||
|
Le profil installé ne correspond plus au dépôt, et les tâches mise le
|
||||||
|
signalent :
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mise run list | grep docker-volume-data # 📝 : installé mais différent
|
||||||
|
mise run diff docker-volume-data
|
||||||
|
```
|
||||||
|
|
||||||
|
```diff
|
||||||
|
--- lxd:docker-volume-data (installé)
|
||||||
|
+++ profiles/containerization/docker-volume-data.profile.yaml (dépôt)
|
||||||
|
@@ -3,7 +3,7 @@
|
||||||
|
devices:
|
||||||
|
docker-data:
|
||||||
|
path: /var/lib/docker
|
||||||
|
- pool: fast
|
||||||
|
+ pool: default
|
||||||
|
source: docker-data
|
||||||
|
type: disk
|
||||||
|
```
|
||||||
|
|
||||||
|
Deux options s'offrent alors à vous :
|
||||||
|
|
||||||
|
- **revenir à la version du dépôt** : `mise run install docker-volume-data`
|
||||||
|
affiche ce diff et demande confirmation avant d'écraser le profil ;
|
||||||
|
- **garder votre version** : `mise run import docker-volume-data` réécrit le
|
||||||
|
fichier du dépôt à partir du profil installé. À relire avec `git diff`, puis
|
||||||
|
à commiter dans votre clone (ou votre fork).
|
||||||
|
|
||||||
|
Un volume ne peut être attaché qu'à une seule instance à la fois. Pour une
|
||||||
|
deuxième instance Docker, copiez le profil et donnez-lui son propre volume :
|
||||||
|
|
||||||
|
```shell
|
||||||
|
lxc storage volume create default docker2-data
|
||||||
|
lxc profile copy docker-volume-data docker2-volume-data
|
||||||
|
lxc profile device set docker2-volume-data docker-data source=docker2-data
|
||||||
|
```
|
||||||
|
|
||||||
|
### Combiner les profils
|
||||||
|
|
||||||
|
Les profils s'empilent au lancement : taille de l'instance (`size-small`,
|
||||||
|
`size-medium`…), snapshots automatiques de l'instance (`snapshots-daily`),
|
||||||
|
volume de données (`docker-volume-data`)…
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
lxc launch ubuntu:lts docker --profile default --profile docker-unprivileged \
|
lxc launch ubuntu:lts docker --profile default --profile docker-unprivileged \
|
||||||
--profile size-medium --profile snapshots-daily
|
--profile docker-volume-data --profile size-medium --profile snapshots-daily
|
||||||
```
|
```
|
||||||
- **Faire le ménage.** L'instance se supprime d'une commande, Docker et ses
|
|
||||||
images avec ; le profil, s'il ne sert plus :
|
### Faire le ménage
|
||||||
|
|
||||||
|
L'instance se supprime d'une commande, Docker avec. Le volume de données, lui,
|
||||||
|
reste : à supprimer explicitement s'il ne sert plus, comme les profils.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
lxc delete --force docker
|
lxc delete --force docker
|
||||||
|
lxc storage volume delete default docker-data
|
||||||
|
lxc profile delete docker-volume-data
|
||||||
lxc profile delete docker-unprivileged
|
lxc profile delete docker-unprivileged
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
name: docker-volume-data
|
name: docker-volume-data
|
||||||
description: "A profile that add a volume for docker data"
|
description: "A profile that add a volume for docker data"
|
||||||
|
# Le volume doit exister avant l'installation du profil (LXD le vérifie) :
|
||||||
|
# lxc storage volume create default docker-data
|
||||||
devices:
|
devices:
|
||||||
docker-data:
|
docker-data:
|
||||||
type: disk
|
type: disk
|
||||||
pool: btrfs
|
pool: default
|
||||||
source: docker-data
|
source: docker-data
|
||||||
path: /var/lib/docker
|
path: /var/lib/docker
|
||||||
Reference in new issue
Block a user