Wie Docker verwendet wird

Installation unter Ubuntu:

sudo apt update

sudo apt install apt-transport-https ca-certificates gnupg-agent software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt install docker-ce docker-ce-cli containerd.io

Installation unter CentOS

sudo yum install -y yum-utils

sudo yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo

sudo yum install docker-ce docker-ce-cli containerd.io

sudo systemctl start docker

Überprüfen Sie die Docker-Installation, indem Sie das hello-world-Image ausführen

sudo docker run hello-world

Sie sollten eine ähnliche Ausgabe wie diese erhalten:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:e7c70bb24b462baa86c102610182e3efcb12a04854e8c582838d92970a09f323
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
        (amd64)
 3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Um Docker-Images (in diesem Fall Ubuntu) herunterzuladen, müssen wir folgendes verwenden:

sudo docker pull ubuntu

Weitere vorkonfigurierte Images finden Sie unter: https://hub.docker.com

wenn Sie sehen möchten, welche Images Sie bereits heruntergeladen haben:

sudo docker images

REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
ubuntu        latest    ba6acccedd29   5 weeks ago    72.8MB
hello-world   latest    feb5d9fea6a5   2 months ago   13.3kB

So erstellen und starten Sie einen Docker-Container:

docker run

z.B.

docker run ubuntu -it

Natürlich können Sie zu diesem Zweck auch einen Container erstellen und ihn später ausführen:

docker create

Wenn Sie den Container in Betrieb nehmen wollen:

docker start <id>

Um den laufenden Container mit interaktivem Modus und tty (TeleTYpewriter) zu öffnen, verwenden Sie folgendes:

docker exec -it <id> /bin/bash

So stoppen/starten/entfernen Sie das Docker-Image:

docker stop/start/rm <id>

Um funktionierende Docker-Images aufzulisten:

docker ps -a