DockerをCentOS7にインストールする方法を丁寧に解説します

CentOS

Docker CEとDocker EE

2014年に登場したDockerは2017年にCEとEEという2つにわかれました。

CE→コミュニティエディション(無償)
EE→エンタープライズエディション(有償)

ここではCEのインストール方法を解説します。

古いパッケージは削除

古いものを過去にインストールしている場合は実行してください。

#yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

必須パッケージのインストール

すでにインストールしている場合は何も起こりませんが一応やっておきましょう

#yum install -y yum-utils device-mapper-persistent-data lvm2

レポジトリのインストール

レポジトリはソースの置き場。安定版のレポジトリを設定します。

#yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
確認
$ yum repolist

読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp-srv2.kddilabs.jp
 * extras: ftp-srv2.kddilabs.jp
 * updates: ftp-srv2.kddilabs.jp
リポジトリー ID                                                             リポジトリー名                                                               状態
base/7/x86_64                                                               CentOS-7 - Base                                                              10,072
docker-ce-stable/7/x86_64                                                   Docker CE Stable - x86_64                                                       108
extras/7/x86_64                                                             CentOS-7 - Extras                                                               463
updates/7/x86_64                                                            CentOS-7 - Updates                                                            1,901
repolist: 12,544

docker-ce-stable/7/x86_64 Docker CE Stable – x86_64
という行があればOKです。

Docker CE のインストール

バージョンの確認

$ yum list docker-ce.x86_64  --showduplicates | sort -r
利用可能なパッケージ
読み込んだプラグイン:fastestmirror, langpacks
インストール済みパッケージ
docker-ce.x86_64	3:20.10.5-3.el7	docker-ce-stable	
docker-ce.x86_64	3:20.10.5-3.el7	@docker-ce-stable
docker-ce.x86_64	3:20.10.4-3.el7	docker-ce-stable	
docker-ce.x86_64	3:20.10.3-3.el7	docker-ce-stable	
docker-ce.x86_64	3:20.10.2-3.el7	docker-ce-stable	
docker-ce.x86_64	3:20.10.1-3.el7	docker-ce-stable	
docker-ce.x86_64	3:20.10.0-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.9-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.8-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.7-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.6-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.5-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.4-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.3-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.2-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.15-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.14-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.13-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.12-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.11-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.10-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.1-3.el7	docker-ce-stable	
docker-ce.x86_64	3:19.03.0-3.el7	docker-ce-stable	
docker-ce.x86_64	3:18.09.9-3.el7	docker-ce-stable	
docker-ce.x86_64	3:18.09.8-3.el7	docker-ce-stable	
docker-ce.x86_64	3:18.09.7-3.el7	docker-ce-stable	
docker-ce.x86_64	3:18.09.6-3.el7	docker-ce-stable	
docker-ce.x86_64	3:18.09.5-3.el7	docker-ce-stable	
docker-ce.x86_64	3:18.09.4-3.el7	docker-ce-stable	
docker-ce.x86_64	3:18.09.3-3.el7	docker-ce-stable	
docker-ce.x86_64	3:18.09.2-3.el7	docker-ce-stable	
docker-ce.x86_64	3:18.09.1-3.el7	docker-ce-stable	
docker-ce.x86_64	3:18.09.0-3.el7	docker-ce-stable	
docker-ce.x86_64	18.06.3.ce-3.el7	docker-ce-stable	
docker-ce.x86_64	18.06.2.ce-3.el7	docker-ce-stable	
docker-ce.x86_64	18.06.1.ce-3.el7	docker-ce-stable	
docker-ce.x86_64	18.06.0.ce-3.el7	docker-ce-stable	
docker-ce.x86_64	18.03.1.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	18.03.0.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	17.12.1.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	17.12.0.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	17.09.1.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	17.09.0.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	17.06.2.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	17.06.1.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	17.06.0.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	17.03.3.ce-1.el7	docker-ce-stable	
docker-ce.x86_64	17.03.2.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	17.03.1.ce-1.el7.centos	docker-ce-stable	
docker-ce.x86_64	17.03.0.ce-1.el7.centos	docker-ce-stable	
Loading	mirror	speeds	from	cached	hostfile
	*	updates:	ftp-srv2.kddilabs.jp
	*	extras:	ftp-srv2.kddilabs.jp
	*	base:	ftp-srv2.kddilabs.jp

もっと詳細を見る場合は

yum info docker-ce.x86_64

読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp-srv2.kddilabs.jp
 * extras: ftp-srv2.kddilabs.jp
 * updates: ftp-srv2.kddilabs.jp
インストール済みパッケージ
名前                : docker-ce
アーキテクチャー    : x86_64
エポック            : 3
バージョン          : 20.10.5
リリース            : 3.el7
容量                : 115 M
リポジトリー        : installed
提供元リポジトリー  : docker-ce-stable
要約                : The open-source application container engine
URL                 : https://www.docker.com
ライセンス          : ASL 2.0
説明                : Docker is a product for you to build, ship and run any application as a
                    : lightweight container.
                    : 
                    : Docker containers are both hardware-agnostic and platform-agnostic. This means
                    : they can run anywhere, from your laptop to the largest cloud compute instance and
                    : everything in between - and they don't require you to use a particular
                    : language, framework or packaging system. That makes them great building blocks
                    : for deploying and scaling web apps, databases, and backend services without
                    : depending on a particular stack or provider.

必要なバージョンをインストールしましょう。

インストール

特にこだわりがない場合はバージョン指定なしで大丈夫です。

# yum install -y docker-ce

バージョン指定する場合は

例) # yum install -y docker-ce-17.09.1.ce-1

※dockerグループが作られるのでコマンド実行するにはこのグループに所属させます

$ usermod -aG docker 【ユーザー名】

起動・確認・自動起動(CentOS7)

起動

Dockerを起動します

# systemctl start docker

何も出力されませんがそれでOKです

確認

テストのためにhello-worldという公式で用意されているイメージを実行してみます。自動的にダウンロードしコンテナを作成し、Dockerに関する概要が出力されたら成功です。

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

自動起動

OS起動時にdockerも自動で起動する設定。必要に応じて行ってください。

自動起動を有効にする

# systemctl enable docker

自動起動になっているか確認する

# systemctl is-enabled docker
enabled

コメント

タイトルとURLをコピーしました