Dockerfileを書いてみた(DockerForWindows上でCentOS7＋Apache＋PerlCGIのサーバ構築編)

#Dockerfileデビューした
Docker For WindowsでDockerfileデビューしたので以下に構築記録を書いておきます

動かした環境は以下です。
![image.png](https://qiita-image-store.s3.amazonaws.com/0/144657/e0587225-dc8b-368c-19ed-936baa853cd1.png)

インストールに使ったのはこちら
![image.png](https://qiita-image-store.s3.amazonaws.com/0/144657/8cd67d01-6d9a-fba9-875d-b57b058c7fb6.png)


やってることは
・CentOS 7.5.1804でバージョン固定してサーバを上げる
・httpd(apache)入れる
・perl入れる
・セッティング入れる
です。

##Dockerfile最終形
急いでる人のためにまず最終形を置いておきますね…
以下になります。

```dockerfile
FROM centos:7.5.1804

LABEL maintainer="Image maintainer ditflame(ditflame@hogehoge)"

# ThisFile  : centos:7.5.1804 (201804_stableVersion) + apache + perlCGI
# Write     : 20180621 ditflame

# usage
# docker build -f Dockerfile_CentOS7.docker -t build:cent7_1804 .
# docker run -d  --rm -p 80:80 -v ${PWD}/www:/var/www --name "cgitest_cent7" build:cent7_1804
# docker run -it --rm -p 80:80 -v ${PWD}/www:/var/www --name "cgitest_cent7" build:cent7_1804 /bin/bash

RUN yum -y update
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
RUN yum -y install httpd perl perl-CGI 

#httpd.conf customize
RUN rm -f /etc/httpd/conf.d/welcome.conf ; \
    cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_bk

RUN cat /etc/httpd/conf/httpd.conf_bk \
    | sed "151 s/AllowOverride None/AllowOverride All/g" \
    | sed "256 s/AllowOverride None/AllowOverride All/g" \
    | sed "s/DirectoryIndex index.html/DirectoryIndex index.html index.htm index.cgi/g" > /etc/httpd/conf/httpd.conf

RUN echo "# ServerTokens (AddByDockerfile)" >>  /etc/httpd/conf/httpd.conf ; \
    echo "ServerTokens Prod" >>  /etc/httpd/conf/httpd.conf ; \
    echo "" >>  /etc/httpd/conf/httpd.conf ; \
    echo "# KeepAlive (AddByDockerfile)" >>  /etc/httpd/conf/httpd.conf ; \
    echo "KeepAlive On" >>  /etc/httpd/conf/httpd.conf

CMD ["httpd","-DFOREGROUND"]

EXPOSE 80
```

ディレクトリ構造は以下です。
※注：**Docker For Windows**では
　**C:\Users直下にファイルを置かないと**、後で出てくる
　docker run -v {PWD}/www:/var/www のくだりで
　**ローカルフォルダにマウントしたと思っていたファイルマウントが
　Docker Volumeを新規に作ってマウント**する挙動を示して
　なかなか困ったことになります。(半日ぐらいこれでハマりました。)

```powershell
PS C:\Users\dockerwork\perlcgi_base> tree /f
フォルダー パスの一覧:  ボリューム SSD
ボリューム シリアル番号は ****-**** です
C:.
│  Dockerfile_CentOS7.docker
│  Dockerfile_CentOS7_bk0620_normalweb.docker
│  Dockerfile_CentOS7_bk0620_normalweb2.docker
│
└─www
    │
    ├─cgi-bin
    │       cgi-lib.pl
    │       jquery.min.js
    │       order_1_v.cgi
    │
    └─html
            index.html

```

##はじめにOSのバージョンを選定する
まずはじめに、

```docker
docker pull -a centos
```
とコマンドを打つとCentOSのイメージがローカルに取れます
そして以下の様なコマンドでローカルに取ったイメージの一覧が取れます。

```powershell
PS C:\Users\dockerwork\perlcgi_base> docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
centos                     7                   49f7960eb7e4        2 weeks ago         200MB
centos                     7.5.1804            49f7960eb7e4        2 weeks ago         200MB
centos                     centos7             49f7960eb7e4        2 weeks ago         200MB
centos                     centos7.5.1804      49f7960eb7e4        2 weeks ago         200MB
centos                     latest              49f7960eb7e4        2 weeks ago         200MB
centos                     6                   70b5d81549ec        2 months ago        195MB
centos                     centos6             70b5d81549ec        2 months ago        195MB
centos                     6.6                 3d7ac13b921a        7 months ago        203MB
centos                     centos6.6           3d7ac13b921a        7 months ago        203MB
centos                     6.7                 000c5746fa52        7 months ago        191MB
centos                     centos6.7           000c5746fa52        7 months ago        191MB
centos                     6.8                 6704d778b3ba        7 months ago        195MB
centos                     centos6.8           6704d778b3ba        7 months ago        195MB
centos                     6.9                 fca4c61d0fa7        7 months ago        195MB
centos                     centos6.9           fca4c61d0fa7        7 months ago        195MB
centos                     7.0.1406            284549eacf84        7 months ago        210MB
centos                     centos7.0.1406      284549eacf84        7 months ago        210MB
centos                     7.1.1503            fbe8925ecf55        7 months ago        212MB
centos                     centos7.1.1503      fbe8925ecf55        7 months ago        212MB
centos                     7.2.1511            0a2bad7da9b5        7 months ago        195MB
centos                     centos7.2.1511      0a2bad7da9b5        7 months ago        195MB
centos                     7.3.1611            66ee80d59a68        7 months ago        192MB
centos                     centos7.3.1611      66ee80d59a68        7 months ago        192MB
centos                     7.4.1708            3afd47092a0e        7 months ago        197MB
centos                     centos7.4.1708      3afd47092a0e        7 months ago        197MB
centos                     5.11                b424fba01172        21 months ago       284MB
centos                     centos5.11          b424fba01172        21 months ago       284MB
centos                     5                   1ae98b2c895d        21 months ago       285MB
centos                     centos5             1ae98b2c895d        21 months ago       285MB
PS C:\Users\dockerwork\perlcgi_base>
```

上の例だと、centos:7.5.1804 が、2 weeks agoで最新のstableである事がわかるので、
これをベースにすることにします。
(centos:latestは常に最新のバージョンを指しますし、良くこれを使えと書いてるサイトや
 情報が多いのですがバージョンブレイクで困らないように、今回はあえて使いません。)

さて、これで1行目のimportコマンドはこうなりました。

```dockerfile
FROM centos:7.5.1804
```

##Webサーバの機能を足す

ここから、Webサーバ機能を追加するため、以下コマンドを足します。
・yumのアップデート

```dockerfile
RUN yum -y update
```

・httpdのインストール

```dockerfile
RUN yum -y install httpd
```

・welcome.confの削除

```dockerfile
RUN rm -f /etc/httpd/conf.d/welcome.conf
```

・デフォルトコマンドの指定(httpd起動のため)

```dockerfile
CMD ["httpd","-DFOREGROUND"]
```

・ポートの記載

```dockerfile
EXPOSE 80
```

これらを踏まえたDockerfileは以下になります。

```dockerfile
FROM centos:7.5.1804

RUN yum -y update
RUN yum -y install httpd
RUN rm -f /etc/httpd/conf.d/welcome.conf

CMD ["httpd","-DFOREGROUND"]

EXPOSE 80
```

さて、このdockerfileでイメージを作成してみましょう…

```powershell
PS C:\Users\dockerwork\perlcgi_base> docker build -f .\Dockerfile_CentOS7_bk0620_normalweb.docker -t build:cent7_1804_web .
```

すると、イメージはできるのですが、
RUN yum -y install httpd　の段でwarningがでます。

![image.png](https://qiita-image-store.s3.amazonaws.com/0/144657/139175b1-7658-f743-f43a-288c65fda266.png)

```
warning: /var/cache/yum/x86_64/7/base/packages/apr-1.4.8-3.el7_4.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
```

どうやらrpmの鍵が足りず、パッケージの真正性が証明できない事が原因のようですね。
ということで、yum installコマンドの前に鍵を取り込みましょう。

```dockerfile
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
```

この修正を終えて、再度イメージを作ると…

```powershell
PS C:\Users\dockerwork\perlcgi_base> docker build -f .\Dockerfile_CentOS7_bk0620_normalweb2.docker -t build:cent7_1804_web2 .
```

結果、warningが発生しなくなりました。
![image.png](https://qiita-image-store.s3.amazonaws.com/0/144657/c2386e74-1d50-e857-fb97-af5614fc3bd1.png)

ここまでで、とりあえずcentos7_5_1804+httpdとしては完成したので動かします。

```powershell
PS C:\Users\dockerwork\perlcgi_base> docker run -d --rm -p 80:80 -v ${PWD}/www:/var/www --name "webtest_cent7" build:cent7_1804_web2
```

動きました。ポートも80でつないでいるので、localhostをブラウザで参照するだけで見えますね。
![image.png](https://qiita-image-store.s3.amazonaws.com/0/144657/7d16d4be-0358-aa68-0d99-e45835668263.png)

ただしcgiは動きません(当たり前)
![image.png](https://qiita-image-store.s3.amazonaws.com/0/144657/6feb689d-f7a8-7606-a05e-5e48ab945f0d.png)

##perlCGIを動くようにする
まず、perlのcgi関連機能を足します。

```dockerfile
RUN yum -y install httpd
↓
RUN yum -y install httpd perl perl-CGI
```

更に、httpd.confのカスタマイズを入れます。

```dockerfile
RUN cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_bk

RUN cat /etc/httpd/conf/httpd.conf_bk \
    | sed "151 s/AllowOverride None/AllowOverride All/g" \
    | sed "256 s/AllowOverride None/AllowOverride All/g" \
    | sed "s/DirectoryIndex index.html/DirectoryIndex index.html index.htm index.cgi/g" > /etc/httpd/conf/httpd.conf

RUN echo "# ServerTokens (AddByDockerfile)" >>  /etc/httpd/conf/httpd.conf ; \
    echo "ServerTokens Prod" >>  /etc/httpd/conf/httpd.conf ; \
    echo "" >>  /etc/httpd/conf/httpd.conf ; \
    echo "# KeepAlive (AddByDockerfile)" >>  /etc/httpd/conf/httpd.conf ; \
    echo "KeepAlive On" >>  /etc/httpd/conf/httpd.conf
```

cgi周りでうまく動かずにハマったポイントとしては、
・httpdのAllowOverride設定が、普通のcentos7で立ち上げた場合であれば
　/var/www/htmlの下(151行目)だけでいいのに、
　なぜか/var/www/cgi-bin側(256行目)にも必要だった
事ぐらいでしょうか。
環境差異による原因なのでしょうか。理由がわからずそっとしています。

最終のログを以下においておきます。

```powershell
PS C:\Users\dockerwork\perlcgi_base> docker build -f Dockerfile_CentOS7.docker -t build:cent7_1804 .
Sending build context to Docker daemon    342kB
Step 1/10 : FROM centos:7.5.1804
 ---> 49f7960eb7e4
Step 2/10 : LABEL maintainer="Image maintainer ditflame(ditflame@hogehoge)"
 ---> Running in e70afc836770
Removing intermediate container e70afc836770
 ---> 902160f308b5
Step 3/10 : RUN yum -y update
 ---> Running in 3d8857772d97
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
 * updates: ftp.jaist.ac.jp
No packages marked for update
Removing intermediate container 3d8857772d97
 ---> 617ab5d4a862
Step 4/10 : RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 ---> Running in c02515edbc82
Removing intermediate container c02515edbc82
 ---> d692e64f26ef
Step 5/10 : RUN yum -y install httpd perl perl-CGI
 ---> Running in 5f89632e70d5
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
 * updates: ftp.jaist.ac.jp
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-80.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-80.el7.centos for package: httpd-2.4.6-80.el7.centos.x86_64
--> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-80.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-80.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-80.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-80.el7.centos.x86_64
---> Package perl.x86_64 4:5.16.3-292.el7 will be installed
--> Processing Dependency: perl-libs = 4:5.16.3-292.el7 for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Socket) >= 1.3 for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl-macros for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl-libs for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(threads::shared) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(threads) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(constant) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Time::Local) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Time::HiRes) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Storable) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Socket) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Scalar::Util) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Pod::Simple::XHTML) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Pod::Simple::Search) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Getopt::Long) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Filter::Util::Call) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(File::Temp) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(File::Spec::Unix) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(File::Spec::Functions) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(File::Spec) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(File::Path) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Exporter) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Cwd) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: perl(Carp) for package: 4:perl-5.16.3-292.el7.x86_64
--> Processing Dependency: libperl.so()(64bit) for package: 4:perl-5.16.3-292.el7.x86_64
---> Package perl-CGI.noarch 0:3.63-4.el7 will be installed
--> Processing Dependency: perl(FCGI) >= 0.67 for package: perl-CGI-3.63-4.el7.noarch
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package centos-logos.noarch 0:70.0.6-3.el7.centos will be installed
---> Package httpd-tools.x86_64 0:2.4.6-80.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
---> Package perl-Carp.noarch 0:1.26-244.el7 will be installed
---> Package perl-Exporter.noarch 0:5.68-3.el7 will be installed
---> Package perl-FCGI.x86_64 1:0.74-8.el7 will be installed
---> Package perl-File-Path.noarch 0:2.09-2.el7 will be installed
---> Package perl-File-Temp.noarch 0:0.23.01-3.el7 will be installed
---> Package perl-Filter.x86_64 0:1.49-3.el7 will be installed
---> Package perl-Getopt-Long.noarch 0:2.40-3.el7 will be installed
--> Processing Dependency: perl(Pod::Usage) >= 1.14 for package: perl-Getopt-Long-2.40-3.el7.noarch
--> Processing Dependency: perl(Text::ParseWords) for package: perl-Getopt-Long-2.40-3.el7.noarch
---> Package perl-PathTools.x86_64 0:3.40-5.el7 will be installed
---> Package perl-Pod-Simple.noarch 1:3.28-4.el7 will be installed
--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
--> Processing Dependency: perl(Encode) for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
---> Package perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 will be installed
---> Package perl-Socket.x86_64 0:2.010-4.el7 will be installed
---> Package perl-Storable.x86_64 0:2.45-3.el7 will be installed
---> Package perl-Time-HiRes.x86_64 4:1.9725-3.el7 will be installed
---> Package perl-Time-Local.noarch 0:1.2300-2.el7 will be installed
---> Package perl-constant.noarch 0:1.27-2.el7 will be installed
---> Package perl-libs.x86_64 4:5.16.3-292.el7 will be installed
---> Package perl-macros.x86_64 4:5.16.3-292.el7 will be installed
---> Package perl-threads.x86_64 0:1.87-4.el7 will be installed
---> Package perl-threads-shared.x86_64 0:1.43-6.el7 will be installed
--> Running transaction check
---> Package perl-Encode.x86_64 0:2.51-7.el7 will be installed
---> Package perl-Pod-Escapes.noarch 1:1.04-292.el7 will be installed
---> Package perl-Pod-Usage.noarch 0:1.63-3.el7 will be installed
--> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-3.el7.noarch
--> Processing Dependency: perl-Pod-Perldoc for package: perl-Pod-Usage-1.63-3.el7.noarch
---> Package perl-Text-ParseWords.noarch 0:3.29-4.el7 will be installed
--> Running transaction check
---> Package perl-Pod-Perldoc.noarch 0:3.20-4.el7 will be installed
--> Processing Dependency: perl(parent) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
--> Processing Dependency: perl(HTTP::Tiny) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
--> Processing Dependency: groff-base for package: perl-Pod-Perldoc-3.20-4.el7.noarch
---> Package perl-podlators.noarch 0:2.5.1-3.el7 will be installed
--> Running transaction check
---> Package groff-base.x86_64 0:1.22.2-8.el7 will be installed
---> Package perl-HTTP-Tiny.noarch 0:0.033-3.el7 will be installed
---> Package perl-parent.noarch 1:0.225-244.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                    Arch       Version                   Repository
                                                                           Size
================================================================================
Installing:
 httpd                      x86_64     2.4.6-80.el7.centos       base     2.7 M
 perl                       x86_64     4:5.16.3-292.el7          base     8.0 M
 perl-CGI                   noarch     3.63-4.el7                base     250 k
Installing for dependencies:
 apr                        x86_64     1.4.8-3.el7_4.1           base     103 k
 apr-util                   x86_64     1.5.2-6.el7               base      92 k
 centos-logos               noarch     70.0.6-3.el7.centos       base      21 M
 groff-base                 x86_64     1.22.2-8.el7              base     942 k
 httpd-tools                x86_64     2.4.6-80.el7.centos       base      89 k
 mailcap                    noarch     2.1.41-2.el7              base      31 k
 perl-Carp                  noarch     1.26-244.el7              base      19 k
 perl-Encode                x86_64     2.51-7.el7                base     1.5 M
 perl-Exporter              noarch     5.68-3.el7                base      28 k
 perl-FCGI                  x86_64     1:0.74-8.el7              base      42 k
 perl-File-Path             noarch     2.09-2.el7                base      26 k
 perl-File-Temp             noarch     0.23.01-3.el7             base      56 k
 perl-Filter                x86_64     1.49-3.el7                base      76 k
 perl-Getopt-Long           noarch     2.40-3.el7                base      56 k
 perl-HTTP-Tiny             noarch     0.033-3.el7               base      38 k
 perl-PathTools             x86_64     3.40-5.el7                base      82 k
 perl-Pod-Escapes           noarch     1:1.04-292.el7            base      51 k
 perl-Pod-Perldoc           noarch     3.20-4.el7                base      87 k
 perl-Pod-Simple            noarch     1:3.28-4.el7              base     216 k
 perl-Pod-Usage             noarch     1.63-3.el7                base      27 k
 perl-Scalar-List-Utils     x86_64     1.27-248.el7              base      36 k
 perl-Socket                x86_64     2.010-4.el7               base      49 k
 perl-Storable              x86_64     2.45-3.el7                base      77 k
 perl-Text-ParseWords       noarch     3.29-4.el7                base      14 k
 perl-Time-HiRes            x86_64     4:1.9725-3.el7            base      45 k
 perl-Time-Local            noarch     1.2300-2.el7              base      24 k
 perl-constant              noarch     1.27-2.el7                base      19 k
 perl-libs                  x86_64     4:5.16.3-292.el7          base     688 k
 perl-macros                x86_64     4:5.16.3-292.el7          base      43 k
 perl-parent                noarch     1:0.225-244.el7           base      12 k
 perl-podlators             noarch     2.5.1-3.el7               base     112 k
 perl-threads               x86_64     1.87-4.el7                base      49 k
 perl-threads-shared        x86_64     1.43-6.el7                base      39 k

Transaction Summary
================================================================================
Install  3 Packages (+33 Dependent packages)

Total download size: 37 M
Installed size: 72 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                              7.9 MB/s |  37 MB  00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-3.el7_4.1.x86_64                                  1/36
  Installing : apr-util-1.5.2-6.el7.x86_64                                 2/36
  Installing : httpd-tools-2.4.6-80.el7.centos.x86_64                      3/36
  Installing : groff-base-1.22.2-8.el7.x86_64                              4/36
  Installing : 1:perl-parent-0.225-244.el7.noarch                          5/36
  Installing : perl-HTTP-Tiny-0.033-3.el7.noarch                           6/36
  Installing : perl-podlators-2.5.1-3.el7.noarch                           7/36
  Installing : perl-Pod-Perldoc-3.20-4.el7.noarch                          8/36
  Installing : 1:perl-Pod-Escapes-1.04-292.el7.noarch                      9/36
  Installing : perl-Text-ParseWords-3.29-4.el7.noarch                     10/36
  Installing : perl-Encode-2.51-7.el7.x86_64                              11/36
  Installing : perl-Pod-Usage-1.63-3.el7.noarch                           12/36
  Installing : 4:perl-macros-5.16.3-292.el7.x86_64                        13/36
  Installing : 4:perl-libs-5.16.3-292.el7.x86_64                          14/36
  Installing : perl-Storable-2.45-3.el7.x86_64                            15/36
  Installing : perl-Exporter-5.68-3.el7.noarch                            16/36
  Installing : perl-constant-1.27-2.el7.noarch                            17/36
  Installing : perl-Time-Local-1.2300-2.el7.noarch                        18/36
  Installing : perl-Socket-2.010-4.el7.x86_64                             19/36
  Installing : perl-Carp-1.26-244.el7.noarch                              20/36
  Installing : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                      21/36
  Installing : perl-PathTools-3.40-5.el7.x86_64                           22/36
  Installing : perl-Scalar-List-Utils-1.27-248.el7.x86_64                 23/36
  Installing : perl-File-Temp-0.23.01-3.el7.noarch                        24/36
  Installing : perl-File-Path-2.09-2.el7.noarch                           25/36
  Installing : perl-threads-shared-1.43-6.el7.x86_64                      26/36
  Installing : perl-threads-1.87-4.el7.x86_64                             27/36
  Installing : perl-Filter-1.49-3.el7.x86_64                              28/36
  Installing : 1:perl-Pod-Simple-3.28-4.el7.noarch                        29/36
  Installing : perl-Getopt-Long-2.40-3.el7.noarch                         30/36
  Installing : 4:perl-5.16.3-292.el7.x86_64                               31/36
  Installing : 1:perl-FCGI-0.74-8.el7.x86_64                              32/36
  Installing : centos-logos-70.0.6-3.el7.centos.noarch                    33/36
  Installing : mailcap-2.1.41-2.el7.noarch                                34/36
  Installing : httpd-2.4.6-80.el7.centos.x86_64                           35/36
  Installing : perl-CGI-3.63-4.el7.noarch                                 36/36
  Verifying  : perl-HTTP-Tiny-0.033-3.el7.noarch                           1/36
  Verifying  : mailcap-2.1.41-2.el7.noarch                                 2/36
  Verifying  : perl-threads-shared-1.43-6.el7.x86_64                       3/36
  Verifying  : perl-Storable-2.45-3.el7.x86_64                             4/36
  Verifying  : perl-Exporter-5.68-3.el7.noarch                             5/36
  Verifying  : perl-constant-1.27-2.el7.noarch                             6/36
  Verifying  : perl-PathTools-3.40-5.el7.x86_64                            7/36
  Verifying  : 4:perl-macros-5.16.3-292.el7.x86_64                         8/36
  Verifying  : centos-logos-70.0.6-3.el7.centos.noarch                     9/36
  Verifying  : 1:perl-parent-0.225-244.el7.noarch                         10/36
  Verifying  : 4:perl-5.16.3-292.el7.x86_64                               11/36
  Verifying  : groff-base-1.22.2-8.el7.x86_64                             12/36
  Verifying  : perl-File-Temp-0.23.01-3.el7.noarch                        13/36
  Verifying  : 1:perl-Pod-Simple-3.28-4.el7.noarch                        14/36
  Verifying  : perl-Time-Local-1.2300-2.el7.noarch                        15/36
  Verifying  : 4:perl-libs-5.16.3-292.el7.x86_64                          16/36
  Verifying  : httpd-tools-2.4.6-80.el7.centos.x86_64                     17/36
  Verifying  : perl-Socket-2.010-4.el7.x86_64                             18/36
  Verifying  : perl-Carp-1.26-244.el7.noarch                              19/36
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                20/36
  Verifying  : httpd-2.4.6-80.el7.centos.x86_64                           21/36
  Verifying  : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                      22/36
  Verifying  : perl-Scalar-List-Utils-1.27-248.el7.x86_64                 23/36
  Verifying  : 1:perl-Pod-Escapes-1.04-292.el7.noarch                     24/36
  Verifying  : 1:perl-FCGI-0.74-8.el7.x86_64                              25/36
  Verifying  : perl-Pod-Usage-1.63-3.el7.noarch                           26/36
  Verifying  : apr-1.4.8-3.el7_4.1.x86_64                                 27/36
  Verifying  : perl-Encode-2.51-7.el7.x86_64                              28/36
  Verifying  : perl-CGI-3.63-4.el7.noarch                                 29/36
  Verifying  : perl-Pod-Perldoc-3.20-4.el7.noarch                         30/36
  Verifying  : perl-podlators-2.5.1-3.el7.noarch                          31/36
  Verifying  : perl-File-Path-2.09-2.el7.noarch                           32/36
  Verifying  : perl-threads-1.87-4.el7.x86_64                             33/36
  Verifying  : perl-Filter-1.49-3.el7.x86_64                              34/36
  Verifying  : perl-Getopt-Long-2.40-3.el7.noarch                         35/36
  Verifying  : perl-Text-ParseWords-3.29-4.el7.noarch                     36/36

Installed:
  httpd.x86_64 0:2.4.6-80.el7.centos        perl.x86_64 4:5.16.3-292.el7
  perl-CGI.noarch 0:3.63-4.el7

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7_4.1
  apr-util.x86_64 0:1.5.2-6.el7
  centos-logos.noarch 0:70.0.6-3.el7.centos
  groff-base.x86_64 0:1.22.2-8.el7
  httpd-tools.x86_64 0:2.4.6-80.el7.centos
  mailcap.noarch 0:2.1.41-2.el7
  perl-Carp.noarch 0:1.26-244.el7
  perl-Encode.x86_64 0:2.51-7.el7
  perl-Exporter.noarch 0:5.68-3.el7
  perl-FCGI.x86_64 1:0.74-8.el7
  perl-File-Path.noarch 0:2.09-2.el7
  perl-File-Temp.noarch 0:0.23.01-3.el7
  perl-Filter.x86_64 0:1.49-3.el7
  perl-Getopt-Long.noarch 0:2.40-3.el7
  perl-HTTP-Tiny.noarch 0:0.033-3.el7
  perl-PathTools.x86_64 0:3.40-5.el7
  perl-Pod-Escapes.noarch 1:1.04-292.el7
  perl-Pod-Perldoc.noarch 0:3.20-4.el7
  perl-Pod-Simple.noarch 1:3.28-4.el7
  perl-Pod-Usage.noarch 0:1.63-3.el7
  perl-Scalar-List-Utils.x86_64 0:1.27-248.el7
  perl-Socket.x86_64 0:2.010-4.el7
  perl-Storable.x86_64 0:2.45-3.el7
  perl-Text-ParseWords.noarch 0:3.29-4.el7
  perl-Time-HiRes.x86_64 4:1.9725-3.el7
  perl-Time-Local.noarch 0:1.2300-2.el7
  perl-constant.noarch 0:1.27-2.el7
  perl-libs.x86_64 4:5.16.3-292.el7
  perl-macros.x86_64 4:5.16.3-292.el7
  perl-parent.noarch 1:0.225-244.el7
  perl-podlators.noarch 0:2.5.1-3.el7
  perl-threads.x86_64 0:1.87-4.el7
  perl-threads-shared.x86_64 0:1.43-6.el7

Complete!
Removing intermediate container 5f89632e70d5
 ---> 5c3432504001
Step 6/10 : RUN rm -f /etc/httpd/conf.d/welcome.conf ;     cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_bk
 ---> Running in 077450b248c5
Removing intermediate container 077450b248c5
 ---> 802a057b1e4d
Step 7/10 : RUN cat /etc/httpd/conf/httpd.conf_bk     | sed "151 s/AllowOverride None/AllowOverride All/g"     | sed "256 s/AllowOverride None/AllowOverride All/g"     | sed "s/DirectoryIndex index.html/DirectoryIndex index.html index.htm index.cgi/g" > /etc/httpd/conf/httpd.conf
 ---> Running in 00ed31973bf5
Removing intermediate container 00ed31973bf5
 ---> 453ea80b4b85
Step 8/10 : RUN echo "# ServerTokens (AddByDockerfile)" >>  /etc/httpd/conf/httpd.conf ;     echo "ServerTokens Prod" >>  /etc/httpd/conf/httpd.conf ;     echo "" >>  /etc/httpd/conf/httpd.conf ;     echo "# KeepAlive (AddByDockerfile)" >>  /etc/httpd/conf/httpd.conf ;     echo "KeepAlive On" >>  /etc/httpd/conf/httpd.conf
 ---> Running in b6e3d0253ef4
Removing intermediate container b6e3d0253ef4
 ---> 5a367e86c9e3
Step 9/10 : CMD ["httpd","-DFOREGROUND"]
 ---> Running in 4159f45c1148
Removing intermediate container 4159f45c1148
 ---> 5e1f8dbab93c
Step 10/10 : EXPOSE 80
 ---> Running in fb4b9d94694d
Removing intermediate container fb4b9d94694d
 ---> e30da6cb1e3a
Successfully built e30da6cb1e3a
Successfully tagged build:cent7_1804
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
PS C:\Users\dockerwork\perlcgi_base> docker run -d  --rm -p 80:80 -v ${PWD}/www:/var/www --name "cgitest_cent7" build:cent7_1804
cc1bfd4cadf941e80ba3c0dec84e7a1a217b6ff4098b711ab88c1fd11d320fb7
PS C:\Users\dockerwork\perlcgi_base>
```

これで、cgiもちゃんと動きました。
![image.png](https://qiita-image-store.s3.amazonaws.com/0/144657/9304abaf-1fb8-772f-9999-b91547ddbd61.png)

以上です。