English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Basisbegriffe von Docker
Docker ist ein Open-Source-Anwendungskontainer-Engine, die es Entwicklern ermöglicht, ihre Anwendungen und Abhängigkeiten in einem tragbaren Container zu verpacken und auf jedem beliebigen Linux-Rechner zu veröffentlichen.
Docker ist eine offene Plattform, die den Prozess der Entwicklung, Testung, Bereitstellung und Deployment von Programmen neu definiert. Docker kann als "Build once, Run anywhere" bezeichnet werden, das bedeutet, ein Mal erstellen und überall ausführen, was Docker vorschlägt.
Erstellen eines Images
Es gibt drei Methoden, um ein Image zu erstellen:
Basierend auf einem bestehenden Container erstellen
Basierend auf lokalen Vorlagen importieren
Basierend auf Dockerfile
Basierend auf einem bestehenden Container erstellen
Hauptnutzung des Befehls "docker commit", Befehlsformat:
docker commit [OPTIONEN] CONTAINER [REPOSITORY[:tag]],主要包括:
-a ,--author="" Autorinformation
-m,--message="" Nachricht zum Commit
-p,--pause=true Pausiert den Container beim Commit
Beispiel:
# docker run -it centos /bin/bash [root@d7e7ac1cbca2 /]# touch test [root@d7e7ac1cbca2 /]# ls anaconda-post.log bin dev etc home lib lib64 verloren+Medium gefunden mnt opt proc root run sbin srv sys test tmp usr var # docker commit -m "Datei hinzufügen" -a "kafeikele" de6 centos_copy 5d318afa9e6f7fdb755db97e29e3860b752f24b0b50e6bfa0b7e457450802c0e # docker images REPOSITORY TAG IMAGE ID ERSTELLT VIRTUELLE GRÖSSE centos_copy latest 5d318afa9e6f 13 Sekunden her 196.7 MB
Basierend auf lokalen Vorlagen importieren
Es wird empfohlen, die von openVZ bereitgestellten Vorlagen zu verwenden, um zu erstellen
https://openvz.org/Herunterladen/Vorlagen/vorhergeformt #cat centos-7-x86_64-minimal.tar.gz.crdownload | docker import - centos:latest
Speichern und Importieren von Images
# docker images centos 7.1.1503 47a77536ad4c 8 Woche(n) her 212.1 MB # docker save -o centos_7.1.tar centos:7.1.1503 # docker load --Eingabe centos_7.1.tar # docker load < centos_7.1.tar
Basierend auf Dockerfile
Weitere Inhalte werden im Detail erläutert
Erster Docker-Container ausführen
# docker run centos echo "hello world" Bild 'centos:latest' kann lokal nicht gefunden werden latest: Ziehen von centos 47d44cb6f252: Pull complete 168a69b62202: Pull complete 812e9d9d677f: Ziehen abgeschlossen 4234bfdd88f8: Pull complete ce20c473cd8a: Ziehen abgeschlossen centos:latest: Das Bild, das Sie ziehen, wurde überprüft. Wichtig: Bildprüfung ist eine technische Vorschaufunktion und sollte nicht zur Bereitstellung von security. Digest: 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
Starting an interactive container
docker run -it centos /bin/bash
*Note:-t indicates specifying a pseudo terminal or terminal in the container-i indicates that we can interact with the STDIN inside the container
Starting 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, and 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 viewing logs, stopping, or deleting 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 ends after one output. When all the unique processes in the container have ended, the container stops. Therefore, if a specific service needs to be run 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 : Running the container in the background
-t : Providing a pseudo terminal
-i : Providing interactive input, usually with “-t” together, if only the “-If the 'i' option is used, the container cannot be exited after it starts
-v : Mapping a volume to the container, e.g.: -p /data/www:/var/www/html
-p : Mapping the container's port to the host machine, e.g.: -p 8080:80
更多命令操作
# docker images 列出本地所有镜像 # docker search centos 从默认镜像仓库搜索镜像 NAME DESCRIPTION STARS OFFICIAL AUTOMATED centos The official build of CentOS. 2767 [OK] ansible/centos7-ansible Ansible on 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 This is docker images of CentOS 7 with dif... 17 [OK] consol/centos-xfce-vnc Centos container with "headless" VNC sessi... 14 [OK] #docker pull centos 下载镜像到本地 #docker create -it ubuntu:latest 创建一个容器 Unable to find image 'ubuntu:latest' locally latest: Pulling from ubuntu 58488e45273c: Pull complete 25810b66099e: Pull complete 6571ba684f54: Pull complete 6ed49a73d8f0: Pull complete c53777cbfc31: Pull complete 56465e1e45d2: Pull complete Digest: sha256:312986132029d622ae65423ca25d3a3cf4510de25c47b05b6819d61e2e2b5420 Status: Downloaded newer image for ubuntu:latest 1330233e50aba7fca99e5914bd28dd89321bc86ec35fb36b4775d3424337c190 docker create 命令创建的容器处于停止状态,需要用docker start 把它启动 # docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1330233e50ab ubuntu:latest "/bin/bash" About a minute ago happy_engelbart docker run-Befehl ist äquivalent dazu, zuerst den docker create-Befehl auszuführen und dann den docker start-Befehl auszuführen # docker run ubuntu /bin/echo "hello world" hello world
Gehen Sie in den Container
Methode 1:
# docker attach a54615a88787 folgt dem Namen oder der ID des Containers, der Container wird beendet, wenn der Benutzer aus dem Container ausgelöst wird, wird nicht oft verwendet
Methode 2:
# docker exec -it a54615a88787 /bin/bash folgt dem Namen oder der ID des Containers
Methode 3:
yum -y install util-linux # docker inspect --format "{{.State.Pid}}" stupefied_cray am Ende ist der Name des Containers 4899 # nsenter --target 4899 --mount --uts --ipc --net --pid
Skript
#!/bin/bash CNAME=$1 CPID=$(docker inspect --format "{{.State.Pid}}" $CNAME) nsenter --target $CPID --mount --uts --ipc --net –pid
Die nachstehend genannten sind die grundlegenden Docker-Befehle, die von mir vorgestellt werden. Ich hoffe, sie sind für Sie hilfreich. Wenn Sie Fragen haben, hinterlassen Sie bitte einen Kommentar, ich werde umgehend antworten. Ich danke auch sehr für die Unterstützung der Website yells教程!
Erklärung: Der Inhalt dieses Artikels wurde aus dem Internet übernommen und gehört dem Urheberrechtsinhaber. Der Inhalt wurde von Internetnutzern freiwillig beigesteuert und hochgeladen. Diese Website besitzt keine Eigentumsrechte und hat den Inhalt nicht manuell bearbeitet. Sie übernimmt auch keine rechtlichen Verantwortlichkeiten. Wenn Sie Inhalte finden, die möglicherweise urheberrechtlich geschützt sind, freuen wir uns über eine E-Mail an: notice#oldtoolbag.com (Bitte ersetzen Sie # durch @, wenn Sie eine Meldung senden, und geben Sie relevante Beweise an. Sobald nachgewiesen wird, dass Inhalte urheberrechtlich geschützt sind, wird diese Website die fraglichen Inhalte sofort löschen.)