LoginSignup
3
2

More than 3 years have passed since last update.

DockerをUbuntu上にインストールする方法

Last updated at Posted at 2021-03-20

Dockerを始めるためには、まずはDocker Engineをインストールしなければならない。

今回は、Ubuntuの環境で行う。(Ubuntu 18.04.4 LTS)

Docker 公式ドキュメント

ディストリビューションについて。

3/20/2021現在フォローされているUbuntuのバージョンはこちら

Ubuntu Groovy 20.10
Ubuntu Focal 20.04 (LTS)
Ubuntu Bionic 18.04 (LTS)
Ubuntu Xenial 16.04 (LTS)

/etc/lsb-releaseにバージョンの情報が記載されている
自分のUbuntuのバージョンを確認する方法としては以下。

$ cat /etc/lsb-release 

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"

Ubuntuにはいろいろなフレーバーあって、xubuntu, lubuntuなどが存在する。
これらのパッケージはUbuntuと同じパッケージを使っていて初期状態が違っているだけでaptコマンドでパッケージを変更すると同じものになる。
上記のコマンドで自分のOSのバージョンが対応していることを確認する。対応していればDockerを使うことができる。

Dockerのインストール方法

インストールする方法は、レポジトリーを使う方法と、パッケージがある。
基本的には、レポジトリーからインストールするが、もしレポジトリーからできなかった場合、パッケージからインストールする。

今回は、レポジトリーのみ紹介する。

インストールの手順

レポジトリーの準備

$ sudo apt-get update

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

Docker公式のGPGキーを追加 

GPGキーについてわからない人はこちら:1分でわかるPGP

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

レポジトリーをセット

$ echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

レポジトリーには3種類ある。

channels details
stable 最新のリリースバージョン
test テストのためのGA(一般公開)前のプレリリース
nightly 次の一般公開前のための最新バージョン

特別な理由がないかぎり、stableを使うので上記をそのまま実行すれば大丈夫。stable以外をインストールしたい場合は、上記コマンドのstable後ろにtestかnightly(または両方)を加える

Linux Mint などを使っている場合の注意点
$(lsb_release -cs) は、自分のディストリビューション名が返ってくる。今回の場合は、bionic.しかし例外としてLinux Mint Tessaなどを使っている人は親ディストリビューションに書き換える。例えば、bionicなど。

Docker Engineをインストール

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

Dockerが正しくインストールされたかの確認コマンド

$ 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/

参考
https://qiita.com/gotchane/items/b323bef0b5fbf91fa690
Docker 公式ドキュメント

3
2
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
3
2