ひゃまだのblog

ひゃまだ(id:hymd3a)の趣味のブログ

Debian 11(Bullseye)にDockerのインストール

(2022-09-17 初稿)

PCのローカルなPythonをできるだけシンプルに保ちたいので、Dockerをインストールすることにした。以下は、自分用のメモ。

Dockerの公式サイトにDebian用のインストール方法の記載がある。

筆者は、初めてインストールするので、古いバージョンのアンインストールはしない。

多くは既にインストール済みだと思うが、念のためにインストール。

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

PGP鍵の取得

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

リポジトリの追加

$ 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のインストール

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

hello-worldイメージの実行によるインストールの確認

$ sudo docker run hello-world

以下の表示のように、correctlyがあれば良い。

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Already exists 
Digest: sha256:62af9efd515a25f84961b70f973a798d2eca956b1b2b026d0a4a63a3b0b6a3f2
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/

一般ユーザでも実行できるように

Debianの場合、以下でUserをdockerグループに追加

$ sudo adduser $USER docker

sudo がなくても実行できることを確認

$ docker run hello-world

(省略  correctlyの表示があればOK)

今後、Python3とTensorflowをDockerで動かす記事をアップする予定。

関連ページ