issue212:tutoriel1
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue212:tutoriel1 [2024/12/27 17:42] – créée auntiee | issue212:tutoriel1 [2025/01/02 18:07] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | So you want to fiddle with containers? Well lxd has been around since 2014, so if you have not, now is your chance! OK all you Ubuntu mechanics, grab that virtual spanner and let’s get cracking!!! That includes YOU, lazy bones, fire up your terminal and rev those engines!! | + | **So you want to fiddle with containers? Well lxd has been around since 2014, so if you have not, now is your chance! OK all you Ubuntu mechanics, grab that virtual spanner and let’s get cracking!!! That includes YOU, lazy bones, fire up your terminal and rev those engines!! |
Now that we have lxd installed and we have grabbed a few containers and we have rolled them around in our gobs, we can start with the next leg of our journey down the rabbit hole. Just a quick recap, you know how to install containers, stop and start them, and create and delete them, but I have not shown you how to install software inside those containers or how to take a snapshot of one. We will cover that today. I mean what use is a container if we cannot interact with it? | Now that we have lxd installed and we have grabbed a few containers and we have rolled them around in our gobs, we can start with the next leg of our journey down the rabbit hole. Just a quick recap, you know how to install containers, stop and start them, and create and delete them, but I have not shown you how to install software inside those containers or how to take a snapshot of one. We will cover that today. I mean what use is a container if we cannot interact with it? | ||
Last week I forgot to mention that, if you add - -vm after an image, it will grab the virtual machine instead. (However, since most of you are already well salted in virtual machines, I will leave it alone). | Last week I forgot to mention that, if you add - -vm after an image, it will grab the virtual machine instead. (However, since most of you are already well salted in virtual machines, I will leave it alone). | ||
- | Do you still remember how to check running machines and images? Well, have a quick look and see if you still have any. If you do, that is great; if you do not, grab the last issue and download an image for us to play with. What you get is up to you, as long as you know how to drive it, I’ll stick to an image of Ubuntu, and an Alpine image, for this lesson. | + | Do you still remember how to check running machines and images? Well, have a quick look and see if you still have any. If you do, that is great; if you do not, grab the last issue and download an image for us to play with. What you get is up to you, as long as you know how to drive it, I’ll stick to an image of Ubuntu, and an Alpine image, for this lesson. |
- | The next sequence I need you to know is lxc exec. If I wanted to execute a bash shell in my container, I’d say: lxc exec - - bash (there is a space between the double dash and the word bash) | + | Alors, vous voulez jouer avec les conteneurs ? Eh bien, lxd existe depuis 2014, donc si ce n'est pas votre cas, vous avez cette chance maintenant ! OK, tous les mécaniciens d' |
+ | |||
+ | Maintenant que nous avons installé lxd, que nous avons récupéré quelques conteneurs et que nous les avons fait rouler dans nos bouches, nous pouvons commencer la prochaine étape de notre voyage dans le terrier du lapin. Juste un bref récapitulatif : vous savez comment installer des conteneurs, les arrêter et les démarrer, les créer et les supprimer, mais je ne vous ai pas montré comment installer un logiciel à l' | ||
+ | |||
+ | La semaine dernière, j'ai oublié de mentionner que, si vous ajoutez --vm après une image, il récupérera la machine virtuelle à la place. (Cependant, comme la plupart d' | ||
+ | |||
+ | Vous souvenez-vous encore de la façon de vérifier les machines et les images en cours d’exécution ? Eh bien, jetez un rapide coup d'œil et voyez si vous en avez encore. Si c’est le cas, c’est parfait ; sinon prenez le dernier numéro et téléchargez une image pour que nous puissions jouer avec. Ce que vous obtenez dépend de vous, à condition que vous savez comment le piloter ; je m’en tiendrai à une image d’Ubuntu et une image Alpine pour cette leçon. | ||
+ | |||
+ | |||
+ | **The next sequence I need you to know is lxc exec. If I wanted to execute a bash shell in my container, I’d say: lxc exec - - bash (there is a space between the double dash and the word bash) | ||
I want you to do the same with your Alpine image. | I want you to do the same with your Alpine image. | ||
Ligne 23: | Ligne 32: | ||
Let’s say I wanted to make changes in my Alpine image. (I’m using Alpine as it is tiny and things happen fast). | Let’s say I wanted to make changes in my Alpine image. (I’m using Alpine as it is tiny and things happen fast). | ||
+ | |||
+ | lxc snapshot alpine snapshot.alpine.0.1** | ||
+ | |||
+ | La séquence suivante que je veux que vous connaissiez est lxc exec. Si je voulais exécuter un shell bash dans mon conteneur, je dirais : lxc exec -- bash (il y a une espace entre le double tiret et le mot bash) | ||
+ | |||
+ | Je veux que vous fassiez la même chose avec votre image Alpine. | ||
+ | |||
+ | Avez-vous obtenu une erreur ? Quelque chose comme l' | ||
+ | |||
+ | C'est parce qu' | ||
+ | |||
+ | Vous voyez ? C'est déjà intéressant et nous ne sommes qu'à la première page ! | ||
+ | |||
+ | ASTUCE : N' | ||
+ | |||
+ | Nous y reviendrons dans un instant. Je veux la viande et les pommes de terre à la fin. | ||
+ | |||
+ | La deuxième chose que je voulais vous montrer *avant de commencer à faire des modifications - était de prendre un instantané de votre conteneur. C'est aussi simple que cela en a l'air : lxc snapshot | ||
+ | |||
+ | Disons que je voulais apporter des modifications à mon image Alpine. (J' | ||
lxc snapshot alpine snapshot.alpine.0.1 | lxc snapshot alpine snapshot.alpine.0.1 | ||
- | OK, fantastic, we took a snapshot, but how do we know if it happened? In that case, we use: lxc info -In my case, lxc info alpine - This will bring up quite a bit of info on your container. | + | |
+ | **OK, fantastic, we took a snapshot, but how do we know if it happened? In that case, we use: lxc info -In my case, lxc info alpine - This will bring up quite a bit of info on your container. | ||
You need to scroll down right to the end to see something similar to the image shown above. | You need to scroll down right to the end to see something similar to the image shown above. | ||
Ligne 46: | Ligne 76: | ||
Yes, you guessed it lxc restore! See you are a pro already! | Yes, you guessed it lxc restore! See you are a pro already! | ||
+ | lxc restore alpine snapshot.alpine.0.1** | ||
+ | |||
+ | OK, fantastique, | ||
+ | |||
+ | Vous devez faire défiler la page jusqu' | ||
+ | |||
+ | Comment cela s' | ||
+ | |||
+ | Maintenant que nous avons des instantanés, | ||
+ | |||
+ | Vous pouvez faire les choses habituelles, | ||
+ | |||
+ | Je veux que vous fassiez dans Alpine la même chose que ce que je viens de faire dans Ubuntu, s'il vous plaît. Créez simplement un dossier et un fichier, rien de compliqué. | ||
+ | |||
+ | J'ai maintenant besoin que vous fassiez un autre instantané et que vous voyiez s'il est là. Dans ma capture d' | ||
+ | |||
+ | Astuce : pour sortir du système d' | ||
+ | |||
+ | Restaurons donc notre snapshot et voyons si notre dossier existe toujours. | ||
+ | |||
+ | Oui, vous l'avez deviné lxc restore ! Vous voyez, vous êtes déjà un pro ! | ||
lxc restore alpine snapshot.alpine.0.1 | lxc restore alpine snapshot.alpine.0.1 | ||
- | Now for the before and after shots (see below). | + | |
+ | **Now for the before and after shots (see below). | ||
As you can see, no fcm folder. And that, in a nutshell, is snapshots. | As you can see, no fcm folder. And that, in a nutshell, is snapshots. | ||
Ligne 62: | Ligne 114: | ||
...but nginx on its own doesn’t do much. So we have to edit the html page served to the public. Also installing the package does not activate the web server, so we will need to get the services running and the server serving, or else we have bupkiss. | ...but nginx on its own doesn’t do much. So we have to edit the html page served to the public. Also installing the package does not activate the web server, so we will need to get the services running and the server serving, or else we have bupkiss. | ||
- | Now, obviously I will be holding your hands here, as I cannot expect you guys to get along with Alpine; after all it is not Ubuntu. Before we start, I’d like you to know that we can continue within our container, but we can also edit our files from outside of the container. Alpine is a very minimal image and you will have only vi to work with (by default). So if you wanted to use, say, emacs from outside of the container, there are ways. (https:// | + | Now, obviously I will be holding your hands here, as I cannot expect you guys to get along with Alpine; after all it is not Ubuntu. Before we start, I’d like you to know that we can continue within our container, but we can also edit our files from outside of the container. Alpine is a very minimal image and you will have only vi to work with (by default). So if you wanted to use, say, emacs from outside of the container, there are ways. (https:// |
+ | Passons maintenant aux photos avant et après (voir ci-dessous). | ||
- | See: https:// | + | Comme vous pouvez le voir, pas de dossier fcm. Et cela, en un mot, ce sont des instantanés. |
+ | |||
+ | Maintenant, chargeons une page Web à partir de notre conteneur. Nous pouvons charger Apache ou Nginx dans notre image Alpine. | ||
+ | |||
+ | Ronnie devra me pardonner, car je vais dépasser l' | ||
+ | |||
+ | Je pense que Nginx est plus moderne et plus populaire, et les gens s'en sortent un peu plus facilement. Cette fois-ci, nous entrons dans notre conteneur Alpine et utilisons apk pour récupérer notre paquet. | ||
+ | |||
+ | apk add nginx | ||
+ | |||
+ | ... mais nginx tout seul ne fait pas grand-chose. Nous devons donc modifier la page HTML délivrée au public. De plus, l’installation du paquet n’active pas le serveur Web et nous devrons donc faire fonctionner les services et le serveur, sinon nous n' | ||
+ | |||
+ | Maintenant, je vais évidemment vous tenir la main ici, car je ne m’attends pas à ce que vous vous entendiez bien avec Alpine ; après tout, ce n’est pas Ubuntu. Avant de commencer, j’aimerais que vous sachiez que nous pouvons continuer dans notre conteneur, mais nous pouvons également éditer nos fichiers depuis l’extérieur du conteneur. Alpine est une image très minimaliste et vous n’aurez que vi pour travailler avec (par défaut). Donc si vous voulez utiliser, par exemple, emacs depuis l’extérieur du conteneur, il existe des moyens. (https:// | ||
+ | |||
+ | |||
+ | **See: https:// | ||
https:// | https:// | ||
Ligne 83: | Ligne 151: | ||
The way we copy our file to the container is to push it. Like down the stairs... Just kidding, like push and pop in programming languages, we will push this to our container. | The way we copy our file to the container is to push it. Like down the stairs... Just kidding, like push and pop in programming languages, we will push this to our container. | ||
+ | |||
+ | lxc file push index.html alpine/ | ||
+ | |||
+ | Voir : https:// | ||
+ | https:// | ||
+ | |||
+ | Donc depuis votre conteneur Alpine, je veux que vous ouvriez un shell et nous éditerons ce fichier : | ||
+ | |||
+ | vi / | ||
+ | |||
+ | OU depuis l' | ||
+ | |||
+ | lxc file edit alpine/ | ||
+ | |||
+ | Ainsi, une fois notre fichier édité, commentez simplement toutes les entrées 404 et rootez /var/www/ (illustré ci-dessous) | ||
+ | |||
+ | Remarquez que dans nano, le fichier est enregistré sous un autre nom, mais si vous allez dans le conteneur et vérifiez le fichier, vous verrez qu'il est enregistré. | ||
+ | |||
+ | Bien ! Pour vous apprendre un autre concept, créons notre page Web dans Ubuntu (illustré ci-dessus). Vous pouvez la rendre aussi simple ou aussi sophistiquée que vous le souhaitez. Le fichier ci-dessus est le mien. | ||
+ | |||
+ | La façon dont nous copions notre fichier dans le conteneur consiste à le pousser. Comme dans les escaliers... Je plaisante, comme push et pop dans les langages de programmation, | ||
lxc file push index.html alpine/ | lxc file push index.html alpine/ | ||
- | Now that we have all our ducks in a row, let’s start our web server on our container. So now I need you to go over to your container and type: | + | |
+ | **Now that we have all our ducks in a row, let’s start our web server on our container. So now I need you to go over to your container and type: | ||
rc-update add nginx default | rc-update add nginx default | ||
Ligne 102: | Ligne 192: | ||
Are we having fun yet? | Are we having fun yet? | ||
- | You know where to write to: misc@fullcirclemagazine.org | + | You know where to write to: misc@fullcirclemagazine.org** |
+ | |||
+ | Maintenant que nous avons tout mis en ordre, démarrons notre serveur Web dans notre conteneur. Donc maintenant, j'ai besoin que vous alliez dans votre conteneur pour saisir : | ||
+ | |||
+ | rc-update add nginx default | ||
+ | |||
+ | Puisque nous l' | ||
+ | |||
+ | service nginx start | ||
+ | |||
+ | Maintenant, récupérons l' | ||
+ | |||
+ | lxc list | ||
+ | |||
+ | Ensuite, nous pouvons utiliser curl pour obtenir le résultat. Je n'ai pas besoin de vous l' | ||
+ | |||
+ | On s' | ||
+ | |||
+ | Vous savez où écrire : misc@fullcirclemagazine.org | ||
issue212/tutoriel1.1735317726.txt.gz · Dernière modification : 2024/12/27 17:42 de auntiee