Debian 11にDockerをインストール

今回は、開発を行う際に便利なDockerのインストールを行います。
インストール手順はDocker Engine インストール(Debian 向け)にあるので、その通り行えば簡単です。

Debian 11のセットアップ

今回は仮想マシンに60GBのHDDを用意してインストールしました。
もちろん、デスクトップ環境なしのSSHサーバーありです。

インストールしたばかりの環境なので、いつものおまじないから

$ su -
# apt update
# apt upgrade

忘れていけないOSバージョンの確認。

OS要件では、Docker Engine をインストールするには、Debian か Raspbian の 64 ビットバージョンが必要とのこと。

  • Debian Bullseye 11 (安定版)
  • Debian Buster 10 (古い安定版)
  • Raspbian Bullseye 11 (安定版)
  • Raspbian Buster 10 (古い安定版)

うーむ、ラズパイで動くのかぁ

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
$ uname -a
Linux debian 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux

OS環境として問題ないことが確認できました。

まずは手始めに sudo をインストールします。

# apt install -y sudo
# visudo

下記のように追加します。

<ユーザー名> ALL=(ALL:ALL) ALL

古いバージョンのアンインストール

インストールされている古い環境をアンインストールします。

$ sudo apt-get remove docker docker-engine docker.io containerd runc

今回は、当然まっさらな環境なので実行しません。

リポジトリのセットアップ

今回は、リポジトリを用いたインストールを行います。

aptのパッケージインデックスを下記の手順で更新します。

$ sudo apt-get update
$ sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release

次にDockerの公式GPG鍵を追加します。

$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

以下のコマンドを使って安定版(stable)リポジトリをセットアップします。

$ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Docker Engine のインストール

aptのパッケージインデックスを更新し、最新版の Docker をインストールします。

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Docker Engine が正しくインストールされていることを確認します。

手始めにバージョンの確認

$ sudo docker version
Client: Docker Engine - Community
 Version:           20.10.14
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 24 01:48:21 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.14
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       87a90dc
  Built:            Thu Mar 24 01:46:14 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.11
  GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc:
  Version:          1.0.3
  GitCommit:        v1.0.3-0-gf46b6ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

今度は、hello-worldを動かしてみます。

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67
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/

さきほど作成したイメージの確認

$ sudo docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   6 months ago   13.3kB

まぁこんな風にサクッとDocker環境は準備できるんですけどね

Linux

次の記事

Dockerでubuntu18.04を動かす