【CentOS7】Dockerインストールと起動(無償版CE)

※CentOS8での動作確認済み、ConoHaVPS上での動作確認済みです。

DockerはLinuxのコンテナ技術を用いて、サーバー情に独立したOS環境を構築でき、そのOSを保存しておくこともできますし、他のサーバーを稼働させたりなど柔軟な使い方ができます。

CentOS7でDockerのインストール手順をまとめました。

「Docker」のインストールと起動手順

まずは、以前にDockerをインストールしており、最新のバージョンに入れ替えたい際は現行のDockerを削除します。

Dockerを新規でインストールし直す際は以下の記事を参考にしてください。

Dockerインストール前の事前準備

CentOS7でDockerをインストールする前に事前準備として、yumをアップデートします。

rootユーザーに昇格します。

# su -

インストール前の事前yumアップデートを実施します。

# yum -y update
# yum -y upgrade

公式リポジトリのインストール

Docker公式ページより、yumの参照するリポジトリを設定します。

# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Docker(CE・無償版)のインストールを実施します。

yum install -y docker-ce docker-ce-cli containerd.io

エラーが発生した場合

Dockerインストール時以下のようなメッセージが発生した場合は、メッセージに従って再インストールを実施します。

(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

以下ではメッセージに従い「–skip-broken」コマンドを追加しました。

[root@sn-ghk01]$ yum install -y docker-ce docker-ce-cli containerd.io --nobest

Docker起動

正常にインストールができれば、Dockerを起動します。

# systemctl start docker

以下、コマンドは次回CentOS起動時に、Dockerが自動で自動するためのコマンドとなります。

# systemctl enable docker

以下で、Dockerがインストールされ、バージョンが最新版となっていることを確認します。

# docker --version
Docker version 19.03.6, build 369ce74a3c
# docker version
Client: Docker Engine - Community
 Version:           19.03.6
 API version:       1.40
 Go version:        go1.12.16
 Git commit:        369ce74a3c
 Built:             Thu Feb 13 01:29:29 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.6
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.16
  Git commit:       369ce74a3c
  Built:            Thu Feb 13 01:28:07 2020
  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
# 

Docker CEが正常にインストールされているか確認

インストールが完了したら以下コマンドで確認します。
ハイライトされているメッセージが表示されれば正常にインストールされたことを確認できます。

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:fc6a51919cfeb2e6763f62b6d9e8815acbf7cd2e476ea353743570610737b752
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/

$

以上がCentOS7のDockerインストール手順となります。




エンジニアのオンライン学習

ITエンジニアにおすすめの教材、オンラインスクールです。
無料からエンジニアの学習ができる教材などまとめているので参考にしてください。

おすすめオンライン教材
自宅で学習ができるオンラインスクール

ITエンジニアの開発・検証・学習としてインターネット上で専用のサーバ(VPS)を利用しましょう!
実務経験はVPSで学べます。



コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)

ABOUT US
げんき☆ひろき
インターネット関連のSEをやっています。 ネットワーク、サーバー、ストレージ、仮想基盤まで幅広く手を出しており、MVNOの構築経験もあります。 現在は、Pythonを使ったプログラミングの開発をしネットワークの自動化ツールを作成しています! Pythonの入門書も作成しているので、ぜひ参考にしてください!