Dockerのインストール

提供: Eospedia
移動: 案内検索
  • 公式の手順に従う。
  • 一応打ったコマンドを記載しておく。(2019年5月14日)


  • 古いバージョンのDockerが入っているので、削除する。
$ sudo apt remove docker docker-engine docker.io containerd runc

以下のようなエラーが出た。

パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
パッケージ 'docker-engine' はインストールされていないため削除もされません
パッケージ 'docker' はインストールされていないため削除もされません
パッケージ 'containerd' はインストールされていないため削除もされません
パッケージ 'docker.io' はインストールされていないため削除もされません
パッケージ 'runc' はインストールされていないため削除もされません

確かにDockerはインストールされているのだが。Dockerの.debファイルをdpkgでインストールしたから?


  • 別の方法試した。
$ sudo dpkg --purge docker-ce

これでアンインストールできた。


  • パッケージインデックスのアップデート
$ sudo apt update


  • (インストール済みなことはわかりつつも一応)HTTPS越しでリポジトリを使うために必要なパッケージのインストール
$ sudo apt-get install \
   apt-transport-https \
   ca-certificates \
   curl \
   gnupg-agent \
   software-properties-common


  • DockerのGPG鍵(リポジトリからダウンロードしたパッケージが正しい配布先のものか検証するために使う公開鍵)を登録する
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -


  • GPG鍵がきちんと登録できたかチェックする(GPG鍵の下8桁で検索)
$ sudo apt-key fingerprint 0EBFCD88
pub   4096R/0EBFCD88 2017-02-22
      フィンガー・プリント = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22

フィンガー・プリントが"9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88"なら、Docker公式リポジトリの鍵を登録できている。


  • x86_64, stable版のDockerリポジトリを追加する。
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"


  • パッケージインデックスの更新
$ sudo apt update
ヒット:1 http://jp.archive.ubuntu.com/ubuntu xenial InRelease
ヒット:2 http://jp.archive.ubuntu.com/ubuntu xenial-updates InRelease                                            
ヒット:3 http://jp.archive.ubuntu.com/ubuntu xenial-backports InRelease                                          
ヒット:4 http://security.ubuntu.com/ubuntu xenial-security InRelease                                   
取得:5 https://download.docker.com/linux/ubuntu xenial InRelease [66.2 kB]
取得:6 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages [8,482 B] 
ヒット:7 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu xenial InRelease

Dockerのパッケージインデックスを読み込めている。


  • インストール
$ sudo apt-get install docker-ce docker-ce-cli containerd.io


# dockerユーザーグループの作成
$ sudo groupadd docker
# ユーザーをdockerグループへ追加
$ sudo usermod -aG docker <ユーザー名>


  • 動作テスト - Hello Worldコンテナの実行 -
$ docker run hello-world

出力は以下。

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:5f179596a7335398b805f036f7e8561b6f0e32cd30a32f5e19d17a3cda6cc33d
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 systemctl enable docker
Synchronizing state of docker.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable docker