DockerをCentOS7にインストール

1.前提

Windows10にVirtualBoxを入れ、その上で動くCentOSのVM環境にDockerをインストールします。

各バージョンは下記の通りです。

  

Windows 10 Pro

VritualBox 5.2.6

CentOS Linux release 7.4.1708 (Core) 

docker-ce-17.12.0.ce-1.el7.centos

 

2.Dockerインストール

2.1.準備(sudo設定)

インストールに使うユーザを"wheel"グループに追加する。

 

# gpasswd -a {USER} wheel

 

2.2.dockerインストール

(1)旧バージョンをアンインストール

$ sudo yum remove docker docker-common docker-selinux docker-engine

 

(2)必要なパッケージをインストール

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

 

(3)リポジトリを追加

$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

 

(4)インデックス更新

$ sudo yum makecache fast

 

(5)インストール可能なバージョンのリストを取得

$ yum list docker-ce --showduplicates | sort -r

----------------------------------------------------------------------

利用可能なパッケージ

読み込んだプラグイン:fastestmirror, langpacks

インストール済みパッケージ

docker-ce.x86_64            17.12.0.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.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.iij.ad.jp

 * extras: mirror.fairway.ne.jp

 * base: mirror.fairway.ne.jp

----------------------------------------------------------------------

 

(6)バージョンを指定してインストール

$ sudo yum install docker-ce-17.12.0.ce-1.el7.centos

 

(7)docker起動

$ sudo systemctl start docker

 

(8)動作確認

$ sudo docker run hello-world

----------------------------------------------------------------------

Hello from Docker!

This message shows that your installation appears to be working correctly.

…省略…

----------------------------------------------------------------------

 

(9)sudoの設定

$ sudo gpasswd -a {USER} docker

 

(10)確認

  • 仮想マシンを再起動

$ sudo reboot

 

  • "hello-world"イメージを利用してdockerが正しくインストールされたことを確認

$ sudo systemctl start docker

$ docker run hello-world

 

3.参考

・「Get Docker CE for CentOS」

・「さわって理解するDocker入門」

・「Dockerイメージの理解とコンテナのライフサイクル」

写真素材のピクスタ