Ubuntu 22.04 に Docker をインストールする

1. 適切なアップデート

sudo apt update

注: 実行結果は次のとおりです。「...」は、インストールの中間出力の内容を省略することを意味します。そうしないと、内容が多すぎます。

root@gt-ubuntu22-04-cmd-v1-0-32gb-100m:/home/ubuntu/ocr# sudo apt update
Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease [270 kB]
Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease [119 kB]
......
Get:48 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/multiverse amd64 c-n-f Metadata [260 B]
Fetched 28.7 MB in 4s (6687 kB/s)                           
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
233 packages can be upgraded. Run 'apt list --upgradable' to see them.

2. 関連する依存関係とツールキットを更新する

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

注: 実行結果は次のとおりです。「...」は、インストールの中間出力の内容を省略することを意味します。そうしないと、内容が多すぎます。

root@gt-ubuntu22-04-cmd-v1-0-32gb-100m:/home/ubuntu/ocr# sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  dirmngr gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm gpgv libcurl4
  python3-software-properties
Suggested packages:
    
....................                                                                                                   

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

3. Dockerイメージソースを設定する

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

注: [OK] は設定が成功したことを意味します

root@gt-ubuntu22-04-cmd-v1-0-32gb-100m:/home/ubuntu/ocr# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK

4. Docker APT ウェアハウス ソースを追加する

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

注: 実行結果は次のとおりです。

root@gt-ubuntu22-04-cmd-v1-0-32gb-100m:/home/ubuntu/ocr# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Repository: 'deb [arch=amd64] https://download.docker.com/linux/ubuntu jammy stable'
Description:
Archive for codename: jammy components: stable
More info: https://download.docker.com/linux/ubuntu
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.sudo apt install docker-ce docker-ce-cli containerd.io

.........

apt  install docker.io      # version 20.10.21-0ubuntu1~22.04.3
apt  install podman-docker  # version 3.4.4+ds1-1ubuntu1.22.04.1
See 'snap info docker' for additional versions.

5. apt を更新して、最新バージョンの docker が後でインストールされるようにします。

sudo apt update

注: 実行結果は次のとおりです。

root@gt-ubuntu22-04-cmd-v1-0-32gb-100m:/home/ubuntu/ocr# sudo apt update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease                  
Hit:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease          
Hit:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease
Hit:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease
Hit:5 https://download.docker.com/linux/ubuntu jammy InRelease           
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
217 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: https://download.docker.com/linux/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.

6. 最新バージョンの docker をインストールする

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

注: 続行するかどうかを尋ねられたら、「Y」を入力してインストールを続行する必要があります。

root@gt-ubuntu22-04-cmd-v1-0-32gb-100m:/home/ubuntu/ocr# sudo apt install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree... Done

......

Do you want to continue? [Y/n] y

......

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

7. Docker の実行ステータスを確認する

sudo systemctl status docker

以下のように、「Active: active (running)」と表示されている場合は、docker が実行中であることを意味し、インストールが完了していれば自動的に docker が実行されます。

root@gt-ubuntu22-04-cmd-v1-0-32gb-100m:/home/ubuntu/ocr# sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-07-26 15:59:21 UTC; 56s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 10753 (dockerd)
      Tasks: 17
     Memory: 27.0M
        CPU: 619ms
     CGroup: /system.slice/docker.service
             └─10753 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

8. Hello world コンテナを実行します。

docker container run hello-world

「Hello from Docker!」が表示されると、コンテナーが正常に実行されたことを意味します。
ここに画像の説明を挿入
「docker ps -a」コマンドを使用して既存のコンテナを表示することもでき、hello world コンテナが実行されたことがわかります。(注: このコンテナはコマンド行を出力した後に終了するのと同じなので、ここでは STATUS = Exited となります)
ここに画像の説明を挿入

整理するのは簡単ではありませんが、親指を立ててください。
整理するのは簡単ではありませんが、親指を立ててください。
整理するのは簡単ではありませんが、親指を立ててください。

おすすめ

転載: blog.csdn.net/qq_40600379/article/details/131950285