Pop!_OSに最新バージョンの「docker」と「docker compose」をインストールする

Pop!_OSに最新バージョンの「docker」と「docker compose」をインストールする

Pop!_OSに最新バージョンの「docker」と「docker compose」をインストールするまでの手順を記述してます。

環境

  • OS Pop!_OS 20.10
  • docker 20.10.5

事前準備

アップデートを行っておきます。

sudo apt update

次に、必要なパッケージをインストールしておきます。

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

公式のGPGキーを登録します。

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 focal stable"

インストールできる候補は、以下のコマンドで確認可能です。

apt-cache policy docker-ce

<出力結果>
docker-ce:
  バージョンテーブル:
 *** 5:20.10.5~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
        100 /var/lib/dpkg/status
     5:20.10.4~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.3~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.2~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.1~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.0~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.15~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.14~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.13~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.12~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.11~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.10~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.9~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages

dockerインストール

事前準備ができたので、dockerのインストールを行います。

sudo apt install docker-ce

バージョンを確認してみます。

docker -v

<出力結果>
Docker version 20.10.5, build 55c4c88

自動起動を有効にしておきます。

sudo systemctl enable --now docker

ステータスも確認します。

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 Fri 2021-04-02 11:48:13 JST; 40s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 206019 (dockerd)
      Tasks: 8
     Memory: 40.8M
     CGroup: /system.slice/docker.service
             └─206019 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

 4月 02 11:48:11 pop-os dockerd[206019]: time="2021-04-02T11:48:11.488718261+09:00" level=warning msg="Your kernel does not support CPU realtime scheduler"
 4月 02 11:48:11 pop-os dockerd[206019]: time="2021-04-02T11:48:11.489148050+09:00" level=warning msg="Your kernel does not support cgroup blkio weight"
 4月 02 11:48:11 pop-os dockerd[206019]: time="2021-04-02T11:48:11.489258847+09:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"
 4月 02 11:48:11 pop-os dockerd[206019]: time="2021-04-02T11:48:11.489499341+09:00" level=info msg="Loading containers: start."
 4月 02 11:48:12 pop-os dockerd[206019]: time="2021-04-02T11:48:12.059760350+09:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon o>
 4月 02 11:48:12 pop-os dockerd[206019]: time="2021-04-02T11:48:12.412203441+09:00" level=info msg="Loading containers: done."
 4月 02 11:48:12 pop-os dockerd[206019]: time="2021-04-02T11:48:12.656705991+09:00" level=info msg="Docker daemon" commit=363e9a8 graphdriver(s)=overlay2 version=20.10.5
 4月 02 11:48:12 pop-os dockerd[206019]: time="2021-04-02T11:48:12.656810588+09:00" level=info msg="Daemon has completed initialization"
 4月 02 11:48:13 pop-os systemd[1]: Started Docker Application Container Engine.
 4月 02 11:48:13 pop-os dockerd[206019]: time="2021-04-02T11:48:13.184441306+09:00" level=info msg="API listen on /run/docker.sock"
lines 1-21/21 (END)

ログインしているユーザーでdockerコマンドが利用できるようにしておきます。

sudo usermod -aG docker ${USER}

一度、ターミナルを抜けるか以下のコマンドを実行します。

su - ${USER}

sudoなしで実行可能にしておきます。

sudo chmod 666 /var/run/docker.sock

動作確認

動作確認のため「hello-world」してみます。

docker run hello-world

<出力結果>
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
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/

問題なければ、削除しておきます。

docker rm $(docker ps -q -a)
docker rmi $(docker images -q)

docker composeインストール

docker composeもインストールしておきます。

こちらのサイトより最新版を確認しておきます。

最新版が1.28.6だったので、こちらをインストールします。

sudo wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.28.6/docker-compose-Linux-x86_64

権限も設定しておきます。

sudo chmod +x /usr/local/bin/docker-compose

バージョンを確認すると、最新のバージョンである「1.28.6」がインストールされていることが確認できます。

docker-compose version

<出力結果>
docker-compose version 1.27.4, build 40524192
docker-py version: 4.3.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019