LoginSignup
1
6

More than 3 years have passed since last update.

DockerをUbuntu18.04にインストールする

Last updated at Posted at 2020-01-29

はじめに

調べれば同様の記事はいくらでもあるけれど、自分の忘備録を兼ねて投稿。
コードは公式のものに準じています。

すること
Docker Engine Community Edition(Docker CE) をインストールする。
環境
Ubuntu 18.04 LTS (Bionic)

Get Docker

Docker Engine の入手(Ubuntu用)
公式を見て、その手順通りにする。以下公式サイト。

サポートされているプラットフォームの確認など。-> Docker Engine overview
インストール手順 -> Get Docker Engine - Community for Ubuntu

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

Dockerの古いバージョン(docker, docker.io, docker-engine)がインストールされている場合には、アンインストールする。

イメージ、コンテナ、ボリューム、およびネットワークを含む/ var / lib / docker /の内容は保持される。
インストールしていなくても実行してよい。

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

2. Docker Engine - Community のインストール

Docerのリポジトリをセットアップしてインストール

  • インストールには複数の方法がある。
  • 推奨されているのはこの方法。
  • インストールやアップグレードのタスクが容易になるらしい。

2.1 インストール可能なパッケージの「一覧」を更新する

$ sudo apt-get update

2.2 aptがHTTPS経由でリポジトリを使用できるように、パッケージをインストールする

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

2.3 Dockerの公式GPG公開鍵を追加

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

公開鍵のフィンガープリントを確認。
"9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88" の後ろ8文字で検索する。

$ sudo apt-key fingerprint 0EBFCD88

pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [  不明  ] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

2.4 リポジトリの設定(x86_64)

ハードウェア名を確認する場合には、unameコマンドを使用する。

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

2.5 最新のバージョンをインストール

最新のものをインストール場合にはこれ。

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

2.6 バージョンを選択してインストール

使用可能なバージョンを表示

$ sudo apt-get update
$ apt-cache madison docker-ce

 docker-ce | 5:19.03.5~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.4~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.3~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 ...

以下のVERSION_STRINGの部分を上記で得られた値に置き換えて実行。

$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

動作確認

$ sudo docker version

Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea838
 Built:             Wed Nov 13 07:29:52 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea838
  Built:            Wed Nov 13 07:28:22 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

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/get-started/
1
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
6