LoginSignup
5
14

More than 3 years have passed since last update.

Docker環境でCentOS7をWindowsに導入するときにつまづいた設定もろもろ

Last updated at Posted at 2019-05-17

はじめに

会社から「DockerでLinuxの環境を使えるよう、CentOS7のイメージを用意してね」と言われたので、社用PC(Windows10)に環境構築しました。

つまづきポイントがあったので、まとめておきます。
いろんなサイトを回って改めて感じたのは、環境って人それぞれだなーってことです。上手くいっている設定は個別の状況によって異なるので、参考になる方もならない方もいると思いますが、ひとつの事例ということで。

(前置き)Dockerとは

【図解】Dockerの全体像を理解する -前編- - Qiita
大変参考になりました。

Dockerインストール手順

大まかな流れは下記の手順で進める。
がしかし、社内プロキシでやっぱりつまづく。。。

Docker Desktop for Windowsをインストールする

Docker Desktop for Windows - Docker Hub
からインストーラをダウンロードして展開。
ダウンロードにはDockerIDの登録が必要。

インストール後はPC再起動を求められる。

ちなみにDockerDesktopを起動するとSign in画面が出てくるが、まずここが通らない。おそらくプロキシの問題だが、サインインできなくても実行には問題ないようだ。
image.png

参考まで、インストール後の環境はこんな感じというのを確認。
Docker for Windowsのインストール後の設定項目 - Qiita

Dockerインストール確認

まずはこちらの記事に従ってバージョン確認。
今更Docker for Windowsをインストールしたのでその備忘録 - Qiita

コマンドプロンプトかPowerShell(どっちでも良いらしい)で下記コマンドを実行。

C:\Users\UserName> docker --version
Docker version 18.09.2, build 6247962
C:\Users\UserName> docker-compose -v
docker-compose version 1.23.2, build 1110ad01

無事インストールができていることがわかった。

Docker実行テスト「Hello World」

このあと、例に倣ってHello Worldを実行しようと試みる。
Docker入門 ~Hello World~ - Qiita

C:\Users\UserName> docker run hello-world

が、エラー。。。

C:\Users\UserName> docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

むむむ。
ここで、Docker DesktopのSettingsに関する設定をググりながら、上から順に色々やってみる。

実行にあたり試したこと

Expose daemon...にチェックを入れてみたり…
WindowsのWSL上にDocker開発環境を立ててみる - Qiita
image.png

DNS ServerをFixedにしてみたり…
Window10に日本語対応CentOS7のdockerコンテナを作ってみた - Qiita
image.png

Proxiesに設定(★)。
image.png

ひととおり設定できそうなところには処置してみたが、まだダメなので、他の手段も調べる。

dockerのプロキシ設定 - Qiita のページに、

~/.docker/config.json
に下記のproxy設定を書き込む。

というのでファイルに追記。

最終的には、「インターネットオプション」のLAN設定に入れてみたりもした。が、ダメ。

その後、セキュリティにやめたほうがいい(どのページで見たか忘れた)と言うので、最初のExpose daemon...のチェックをまた外してみたり。

プロキシ設定の結論

色々やった結果、シンプルにプロキシの設定だけやればよかった模様。
Proxy環境下でDocker for Windowsを使う - Qiita

つまり、上記の★のみ設定、それ以外はすべて初期値に変更する(戻す)ことで、Hello Worldが実行できた!

C:\Users\UserName> docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:6f744a2005b12a704d2608d8070a494ad1145636eeb74a570c56b94d94ccdbfc
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/

いえーい。いやあ良かった良かった。

CentOS 7の実行テスト

DockerでCentOS 7のイメージを利用してみよう | WEB ARCH LABO
を参考に。
詳細は上記ページに従って進めてもらえればと思うが、

C:\Users\UserName> docker pull centos:centos7

でイメージの取得、

C:\Users\UserName> docker run -it -d --name centos7 centos:centos7

でコンテナの作成・起動。

C:\Users\UserName> docker stop centos7

で停止する。

おわりに

というわけで、ほぼほぼプロキシ設定の解決に時間を費やしました。
同じような環境の方がいて、本記事が参考になれば幸いです。

本文内で参照したページまとめ

5
14
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
5
14