English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
concepts fondamentaux de docker
Docker est un moteur d'application containerisée open source qui permet aux développeurs de conditionner leurs applications et leurs dépendances dans un conteneur portable et de les publier sur n'importe quel ordinateur Linux populaire.
Docker est une plateforme ouverte qui redéfinit le processus de développement, de test, de distribution et de déploiement des programmes, Docker peut être appelé 'build once, run anywhere', c'est-à-dire construire une fois, exécuter partout, c'est ce que Docker propose 'Build once, Run anywhere'
créer une image
Il y a trois méthodes pour créer une image :
créer à partir d'un conteneur existant
Importation basée sur le modèle local
Basé sur dockerfile
créer à partir d'un conteneur existant
L'utilisation principale de la commande docker commit, la syntaxe de la commande :
docker commit [OPTIONS] CONTAINER [REPOSITORY[:tag]] comprend principalement :
-a ,--author="" informations de l'auteur
-m,--message="" message de soumission
-p,--pause=true arrêter le conteneur lors de la soumission
par exemple :
# docker run -it centos /bin/bash [root@d7e7ac1cbca2 /]# touch test [root@d7e7ac1cbca2 /]# ls anaconda-post.log bin dev etc home lib lib64 perdu+média trouvé mnt opt proc root run sbin srv sys test tmp usr var # docker commit -un "add a file" -un "kafeikele" de6 centos_copy 5d318afa9e6f7fdb755db97e29e3860b752f24b0b50e6bfa0b7e457450802c0e # docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos_copy latest 5d318afa9e6f 13 secondes auparavant 196.7 MB
Importation basée sur le modèle local
Il est recommandé d'utiliser les modèles fournis par openVZ pour créer
https://openvz.org/Télécharger/modèles/précréé #cat centos-7-x86_64-minimal.tar.gz.crdownload | docker import - centos:latest
Enregistrer et importer des images
# docker images centos 7.1.1503 47a77536ad4c 8 semaines auparavant 212.1 MB # docker save -o centos_7.1.tar centos:7.1.1503 # docker load --input centos_7.1.tar # docker load < centos_7.1.tar
Basé sur dockerfile
Les détails suivants sont détaillés
Lancement du premier conteneur docker
# docker run centos echo "hello world" Incapable de trouver l'image 'centos:latest' localement latest: Traction à partir de centos 47d44cb6f252: Téléchargement terminé 168a69b62202: Téléchargement terminé 812e9d9d677f: Traction complète 4234bfdd88f8: Téléchargement terminé ce20c473cd8a: Traction complète centos:latest: L'image que vous tirez a été vérifiée. Important : la vérification de l'image est une fonctionnalité en avant-première technique et ne doit pas être dépendue pour fournir security. Résumé : sha256:3aaab9f1297db9b013063c781cfe901e2aa6e7e334c1d1f4df12f25ce356f2e5 Status: Downloaded a newer image for centos:latest hello world
Command description:
docker run: Standard container start command
centos: The name of the image, default is latest
echo and the following content: The command executed after the container starts
Start an interactive container
docker run -it centos /bin/bash
*Note:-t indicates that a pseudo-terminal or terminal is specified in the container-i indicates that we can interact with the STDIN inside the container
Start a docker container as a service
If you actually test, you may have found that the first 'hello world' container exits after executing the echo command, while the second interactive container exits as soon as the user exits the current container's bash. This clearly does not meet the requirements of a service running for a long time, so docker run provides ‘-d' parameter can be used to start the container as a daemon process.
docker run -d centos /bin/bash -c "while true; do echo Docker,hello world; sleep 2; <br>179fc7f17c358834364d23112aa26d6a9e1875b2281563720425f62a8f1b5c33
This long string is called the container ID. It is the unique identifier of the container, so we can use it to operate the container, such as view logs, stop or delete containers, etc.
dock logs 179fc7f17c358834364d
And why use a dead loop to output?
Because if it is not a dead loop, the process in the container will end after one output. When all the unique processes in the container have ended, the container stops. Therefore, if you want to run a specific service in the container, this service itself must also be run in the container as a daemon process.
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Main options:
-d : Run the container in the background
-t : Provide a pseudo-terminal
-i : Provide interactive input, usually with “-t” together, if only the “-If the 'i' option is used, the container cannot be exited after it starts
-v : Map a volume to the container, such as: -p /data/www:/var/www/html
-p : Map the container's port to the host, such as: -p 8080:80
Plus de commandes
# docker images Listes toutes les images locales # docker search centos Rechercher des images dans le dépôt par défaut NOM DESCRIPTION ÉTOILES OFFICIEL AUTOMATIQUE centos La version officielle de CentOS. 2767 [OK] ansible/centos7-ansible Ansible sur Centos7 90 [OK] jdeathe/centos-ssh CentOS-6 6.8 x86_64 / CentOS-7 7.2.1511 x8... 42 [OK] jdeathe/centos-ssh-apache-php CentOS-6 6.8 x86_64 - Apache / PHP / PHP M... 21 [OK] nimmis/java-centos Voici les images Docker de CentOS 7 with dif... 17 [OK] consol/centos-xfce-vnc Conteneur CentOS avec "sans tête" session VNC... 14 [OK] #docker pull centos Télécharger l'image vers le local #docker create -it ubuntu:latest Créer un conteneur Impossible de trouver l'image 'ubuntu:latest' localement latest: Téléchargement depuis ubuntu 58488e45273c: Téléchargement terminé 25810b66099e: Téléchargement terminé 6571ba684f54: Téléchargement terminé 6ed49a73d8f0: Téléchargement terminé c53777cbfc31: Téléchargement terminé 56465e1e45d2: Téléchargement terminé Résumé : sha256:312986132029d622ae65423ca25d3a3cf4510de25c47b05b6819d61e2e2b5420 Statut : Téléchargement d'une nouvelle image pour ubuntu:latest 1330233e50aba7fca99e5914bd28dd89321bc86ec35fb36b4775d3424337c190 Le conteneur créé par la commande docker create est en état arrêté, il faut utiliser docker start pour le démarrer # docker ps -a IDENTIFIANT DE CONTAINER IMAGE COMMANDE CRÉÉE ÉTAT PORTS NOMS 1330233e50ab ubuntu:latest "/bin/bash" Il y a environ une minute happy_engelbart La commande docker run est équivalente à exécuter d'abord la commande docker create, puis la commande docker start # docker run ubuntu /bin/echo "hello world" hello world
Entrer dans le conteneur
Méthode 1 :
# docker attach a54615a88787 suit au nom ou à l'ID du conteneur, le conteneur Docker quitte également après la sortie, ce n'est pas souvent utilisé
Méthode 2 :
# docker exec -it a54615a88787 /bin/bash suit au nom ou à l'ID du conteneur
Méthode 3 :
yum -y install util-linux # docker inspect --format "{{.State.Pid}}" stupefied_cray à la fin est le nom du conteneur 4899 # nsenter --target 4899 --mount --uts --ipc --net --pid
script
#!/bin/bash CNAME=$1 CPID=$(docker inspect --format "{{.State.Pid}}" $CNAME) nsenter --target $CPID --mount --uts --ipc --net –pid
Les commandes de base de Docker que l'éditeur vous présente ci-dessus, j'espère qu'elles vous seront utiles. Si vous avez des questions, laissez-moi un message, je vous répondrai à temps. Je vous remercie également de votre soutien au site de tutoriels Yell.
Déclaration : Le contenu de cet article est recueilli sur Internet, la propriété intellectuelle appartient à l'auteur original, le contenu est fourni par les utilisateurs d'Internet, le site Web ne détient pas de droits de propriété, n'a pas été traité par l'éditeur humain et n'assume aucune responsabilité juridique. Si vous trouvez du contenu suspect de violation de droits d'auteur, veuillez envoyer un e-mail à : notice#oldtoolbag.com (au moment de l'envoi d'un e-mail, veuillez remplacer # par @ pour signaler une violation de droits d'auteur, fournissez des preuves pertinentes. Une fois vérifié, le site supprimera immédiatement le contenu suspect de violation de droits d'auteur.)