LoginSignup
4
4

More than 3 years have passed since last update.

プロキシー環境でCentOS7.5に最新バージョンのDockerをインストールする

Last updated at Posted at 2018-09-01

はじめに

公式ドキュメントを参考し、CentOSに最新バージョンのDockerをインストールしました。
メモとしてインストール手順を残しておきます。

環境

  • CentOS:7.5.18.04
  • Docker:18.06.1-ce
  • ネットワーク:プロキシーあり  

    - 環境変数にhttp_proxy,https_proxy,no_proxy設定済み 

手順

古いバージョンのものをアンインストールします

sudo yum remove docker  docker-client  docker-client-latest  docker-common  docker-latest  docker-latest-logrotate  docker-logrotate  docker-selinux  docker-engine-selinux  docker-engine

必要なパッケージをインストールします

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

リポジトリを追加します

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

Docker CEをインストールします

sudo -E yum install docker-ce -y 

自動起動を有効化します

sudo systemctl enable docker

Docker daemon用プロキシーを設定します

こちらの設定は、Dockerイメージをpull,pushする時に使用するプロキシーです。

echo [Service]>docker-http-proxy.conf
echo Environment=\"HTTP_PROXY=$http_proxy\" \"HTTPS_PROXY=$https_proxy\" \"NO_PROXY=$no_proxy\" >>docker-http-proxy.conf
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo mv docker-http-proxy.conf /etc/systemd/system/docker.service.d/http-proxy.conf

Docker daemon設定をリロードします。

sudo systemctl daemon-reload

Dockerを起動します

sudo systemctl start docker

Docker daemon用プロキシー設定を確認します。

[user@localhost ~]$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://192.168.56.1:3128 HTTPS_PROXY=http://192.168.56.1:3128 NO_PROXY=127.0.0.1,localhost

設定に問題がなければ、上記のような内容が表示されます。

インストールしたDockerをバージョン確認します

[user@localhost ~]$ docker -v
Docker version 18.06.1-ce, build e68fc7a

hello-worldを実行します

[user@localhost ~]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9db2ca6ccae0: Pull complete
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
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/engine/userguide/

コンテナー用プロキシー設定

こちらの設定は、コンテナーからアクセスする時に使用するプロキシーです。
Dockerバージョンが17.06以上であることが前提になります。

 設定ファイル作成

下記のように設定ファイルを編集します。

config.json
{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://192.168.56.1:3128",
     "httpsProxy": "http://192.168.56.1:3128",
     "noProxy": "127.0.0.1,localhost"
   }
 }
}

 設定ファイルを移動

このファイルはDockerクライアントの実行ユーザーの~/.docker/に配置します。
sudoで実行する場合は/root/.docker/に配置します。

sudo mkdir /root/.docker
sudo mv config.json /root/.docker/

sudoなしで実行する場合、~/.docker/に配置します。

mkdir .docker
mv config.json .docker/

 コンテナー用プロキシー設定確認

[user@localhost ~]$ sudo docker run centos curl -s google.co.jp
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
256b176beaff: Pull complete
Digest: sha256:6f6d986d425aeabdc3a02cb61c02abb2e78e57357e92417d6d58332856024faf
Status: Downloaded newer image for centos:latest
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.co.jp/">here</A>.
</BODY></HTML>

sudoなしでDockerを実行するため、ユーザーをDockerグループに追加します

セキュリティが弱くなります

sudo usermod -aG docker $USER

実行後、再ログインすると、sudoなしでdockerコマンドを実行できるになります。

参考資料

4
4
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
4
4