03-6416-1579

平日 10:00-18:00

Red Hat Enterprise Linux 7 / CentOS 7 に Docker をインストールする


Docker のリポジトリを設定する

  1. 必要なパッケージをインストールします。
    CentOS 7 は、デフォルトでは一般ユーザが sudo できないこと、また root ユーザのパスワードが必須なので root ユーザで実行します。
    # yum install -y yum-utils device-mapper-persistent-data lvm2
  2. レポジトリを追加します。
    # yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Docker をインストールする

最新版の Docker をインストールします。

最新版をインストールする

  1. 最新版をインストールします。
    # yum install docker-ce docker-ce-cli containerd.io
    なお、Red Hat Enterprise Linux 8 等で docker-ce と競合するパッケージ(podman 等)がインストールされていると、「runc と競合しています」のようなメッセージを出力してインストールに失敗する場合があります。
    その場合は以下のコマンドで強制的に競合を解消してインストールすることが可能です。なお、docker-ce と競合するパッケージについては動作しなくなる可能性がありますので、対象ホストで docker-ce をインストールしても問題無いか事前に確認することをお勧めします。
    # yum install docker-ce docker-ce-cli containerd.io --allowerasing

Docker デーモンを起動する

  1. Docker デーモンを起動します。
    # systemctl start docker
  2. Docker をブート時に自動起動するには、次のように実行します。
    # systemctl enable docker

Docker に Proxy を設定する

Docker イメージを取得するためには外部ネットワークへのアクセスが必要です。直接外部ネットワークにアクセスすることができず Proxy サーバを経由している場合はDocekrに Proxy の設定が必要になります。直接外部ネットワークにアクセスすることが可能な場合には、Proxy の設定は不要です。

  1. docker.service.d ディレクトリを作成します。
    # mkdir -p /etc/systemd/system/docker.service.d
  2. /etc/systemd/system/docker.service.d/http-proxy.conf を作成し HTTP_PROXY および HTTPS_PROXY 環境変数を追加します。
    # vi /etc/systemd/system/docker.service.d/http-proxy.conf
    [Service]
      Environment="HTTP_PROXY=http://proxy.example.com:8080/"
      Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
  3. 変更を適用します。
    # systemctl daemon-reload
  4. Docker を再起動します。
    # systemctl restart docker
  5. 変更が適用されているか確認するため、以下のコマンドを実行します。
    # systemctl show --property=Environment docker

Docker の動作確認をする

  1. 動作確認のため Hello world サンプル docer イメージを取得して実行します。
    # docker run --rm hello-world
    # docker run --rm hello-world
    Unable to find image 'hello-world:latest' locally
    Trying to pull repository docker.io/library/hello-world ... 
    latest: Pulling from docker.io/library/hello-world
    1b930d010525: Pull complete 
    Digest: sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e4194f4ee23e415e1064
    Status: Downloaded newer image for docker.io/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/
  2. サンプルdocerイメージを消去します。
    # docker rmi hello-world