Ubuntu 18.04LTSにDocker-CE導入

Pocket

概要

Kubernetesクラスタを構築する為、Ubuntu 18.04にdocker-ce(community edition)を導入します。
環境は大まかにはこんな感じです。

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"

Docker公式に英語版のドキュメントが用意されていますので、今回はこれをベースに導入を行います。

1.導入済みのdockerのアンインストール

Ubuntuのbionic beaverリポジトリにはdockerが用意されています。今回はDocker公式のリポジトリより最新のdockerを導入する為
既に導入済みのdockerを削除します。

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

この場合でも、既に構築済みの関連ファイル(/var/lib/dockerに存在するもの)は保護されます。誤ってapt-get purgeしないようにしてください。

2.レポジトリの追加

aptのリポジトリインデックスを最新の状態にアップデートします。必ずしも必要ではありませんが、念のため実行してください。

$ sudo apt-get update

aptがリポジトリをHTTPSで利用できるようにするために、下記のパッケージを導入します。公式のドキュメントには他のパッケージも記載されて
いますが、Bionic Beaverの初期インストール状態ですべて導入済みでした。(14.04LTS等も同ドキュメントでサポートしている為かと思います。)

$ sudo apt-get install apt-transport-https

DockerのGPG鍵をインポートします。

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

今回はUbuntuに導入する為、Ubuntuレポジトリ用のGPGキーをインポートしました。他にも、下記のOS向けのレポジトリが用意されて
いるようです。

centos/                                     2018-07-28 09:12  -
debian/                                     2018-07-28 09:12  -
fedora/                                     2018-07-28 09:12  -
raspbian/                                   2018-07-28 09:12  -
static/                                     2018-07-28 08:51  -
ubuntu/                                     2018-07-28 09:12  -

常にstableリリースを導入するように、レポジトリをセットアップします。stableの他にedgeリリース、testリリースが用意されています。

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

3.docker-ceの導入

再度、aptのリポジトリインデックスを最新の状態にアップデートします。

$ sudo apt-get update

docker-ceをインストールします。バージョンを指定して導入する場合にはdocker-ce=<version>で導入できます。

$ sudo apt-get install docker-ce

dockerが正しく導入されているか、hello-worldを表示して確認します。

$ sudo docker run hello-world

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/engine/userguide/

 

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください