Outils pour utilisateurs

Outils du site


issue212:tutoriel1

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
issue212:tutoriel1 [2024/12/27 17:42] – créée auntieeissue212: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'Ubuntu, prenez cette clé virtuelle et mettons-nous au travail !!! Cela vous inclut, paresseux, démarrez votre terminal et faites tourner ces moteurs !! 
 + 
 +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'intérieur de ces conteneurs ou comment prendre un instantané de l'un d'eux. Nous allons en parler aujourd'hui. Je me demande à quoi peut servir un conteneur si nous ne pouvons pas interagir avec lui ! 
 + 
 +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'entre vous sont déjà bien calés dans les machines virtuelles, je vais le laisser de côté). 
 + 
 +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'image ci-dessous ?
 +
 +C'est parce qu'Alpine ne contient pas bash. Je vous suggère d'essayer sh.
 +
 +Vous voyez ? C'est déjà intéressant et nous ne sommes qu'à la première page !
 +
 +ASTUCE : N'oubliez pas que vous êtes connecté au conteneur en tant que root : faites attention à ce que vous faites !
 +
 +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'utilise Alpine car il est petit et les choses vont vite.)
  
 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, nous avons pris un instantané, mais comment savoir si cela s'est produit ? Dans ce cas, nous utilisons : lxc info ; dans mon cas, lxc info alpine. Cela fera apparaître pas mal d'informations sur votre conteneur.
 +
 +Vous devez faire défiler la page jusqu'à la fin pour voir quelque chose de similaire à l'image ci-dessus.
 +
 +Comment cela s'est-il passé, avez-vous fait un instantané ? Si c'est le cas, je veux que vous en fassiez un à partir de l'autre conteneur en cours d'exécution que vous avez sur votre système. J'ai Ubuntu, vous avez peut-être autre chose. Allez-y, j'attendrai.
 +
 +Maintenant que nous avons des instantanés, je peux vous montrer comment jouer avec vos images.
 +
 +Vous pouvez faire les choses habituelles, comme vous le feriez avec votre système à la maison ; vous pouvez le mettre à jour, etc. Allez-y et créez un dossier quelque part sur le conteneur.
 +
 +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'écran, vous pouvez voir que j'en ai 2 (juste après le mot CONTAINER).
 +
 +Astuce : pour sortir du système d'exploitation invité, tapez simplement exit.
 +
 +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://discuss.linuxcontainers.org/t/edit-file-from-lxc-container-via-gedit-or-pluma/3008). Then, I had to look up where the files are... hehehe. (OK, honestly, I went through the folders to find it, but I want to look professional for you guys). I told you guys I’m not a programmer. +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://discuss.linuxcontainers.org/t/edit-file-from-lxc-container-via-gedit-or-pluma/3008). Then, I had to look up where the files are... hehehe. (OK, honestly, I went through the folders to find it, but I want to look professional for you guys). I told you guys I’m not a programmer. **
  
 +Passons maintenant aux photos avant et après (voir ci-dessous).
  
-See: https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/+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'espace qui m'est alloué dans le magazine, mais nous avons beaucoup de choses à couvrir et 1 000 mots ne suffiront pas. (Je ne voudrais pas non plus prolonger cela sur trop de numéros, car les gens perdraient alors tout intérêt) [Tu es pardonné - Ronnie]. 
 + 
 +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'aurons que du caca. 
 + 
 +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://discuss.linuxcontainers.org/t/edit-file-from-lxc-container-via-gedit-or-pluma/3008). Ensuite, j’ai dû chercher où se trouvent les fichiers... hehehe. (OK, honnêtement, j’ai parcouru les dossiers pour les trouver, mais je veux avoir l’air professionnel pour vous les gars). Je vous ai dit que je ne suis pas un programmeur. 
 + 
 + 
 +**See: https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/
 https://documentation.ubuntu.com/lxd/en/latest/reference/manpages/lxc/file/edit/ https://documentation.ubuntu.com/lxd/en/latest/reference/manpages/lxc/file/edit/
  
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/var/www/index.html**
 +
 +Voir : https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/
 +https://documentation.ubuntu.com/lxd/en/latest/reference/manpages/lxc/file/edit/
 +
 +Donc depuis votre conteneur Alpine, je veux que vous ouvriez un shell et nous éditerons ce fichier :
 +
 +vi /etc/nginx/http.d/default.conf
 +
 +OU depuis l'extérieur :
 +
 +lxc file edit alpine/etc/nginx/http.d/default.conf
 +
 +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, nous allons le pousser vers notre conteneur.
  
 lxc file push index.html alpine/var/www/index.html lxc file push index.html alpine/var/www/index.html
  
-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'avons ajouté au niveau d'exécution par défaut, nginx devrait démarrer automatiquement. Et nous démarrons le service avec : 
 + 
 +service nginx start 
 + 
 +Maintenant, récupérons l'adresse IP (affichée en haut à droite) : 
 + 
 +lxc list 
 + 
 +Ensuite, nous pouvons utiliser curl pour obtenir le résultat. Je n'ai pas besoin de vous l'expliquer, vous êtes brillants ; ou vous pouvez l'ouvrir dans votre navigateur, en utilisant l'adresse IP. 
 + 
 +On s'amuse bien ? 
 + 
 +Vous savez où écrire : misc@fullcirclemagazine.org
  
issue212/tutoriel1.1735317726.txt.gz · Dernière modification : 2024/12/27 17:42 de auntiee