Apache2.2.29のオフィシャルDockerイメージを使ってみる

##公式で公開されているApache

* 2.2.29、2.2
* 2.4.12、2.4、2、latest

公式：https://github.com/docker-library/docs/tree/master/httpd

今回は、2.2.29を導入してみます。
なお、社内プロキシ環境であるためちょくちょく修正しています

憎きプロキシめ…。

##環境

```bash
[root@master httpd]# docker version
Client version: 1.6.2.el7
Client API version: 1.18
Go version (client): go1.4.2
Git commit (client): c3ca5bb/1.6.2
OS/Arch (client): linux/amd64
Server version: 1.6.2.el7
Server API version: 1.18
Go version (server): go1.4.2
Git commit (server): c3ca5bb/1.6.2
OS/Arch (server): linux/amd64
[root@master httpd]#
[root@master httpd]# uname -a
Linux master 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
```


##Dockerfileの作成

公式よりDockerfileを取得し、ローカルへコピーします
https://github.com/docker-library/httpd/blob/63cd0ad57a12c76ff70d0f501f6c2f1580fa40f5/2.2/Dockerfile


```bash
mkdir /export/docker/httpd
cd /export/docker/httpd

vi Dockerfile
```

###Dockerfile
```vim
FROM debian:jessie

# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
#RUN groupadd -r www-data && useradd -r --create-home -g www-data www-data

ENV HTTPD_PREFIX /usr/local/apache2
ENV PATH $PATH:$HTTPD_PREFIX/bin
RUN mkdir -p "$HTTPD_PREFIX" \
	&& chown www-data:www-data "$HTTPD_PREFIX"
WORKDIR $HTTPD_PREFIX

# install httpd runtime dependencies
# https://httpd.apache.org/docs/2.4/install.html#requirements
RUN apt-get update \
	&& apt-get install -y --no-install-recommends \
		libapr1 \
		libaprutil1 \
		libpcre++0 \
		libssl1.0.0 \
	&& rm -r /var/lib/apt/lists/*

# see https://httpd.apache.org/download.cgi#verify
RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B1B96F45DFBDCCF974019235193F180AB55D9977

ENV HTTPD_VERSION 2.2.29
ENV HTTPD_BZ2_URL https://www.apache.org/dist/httpd/httpd-$HTTPD_VERSION.tar.bz2

RUN buildDeps=' \
		ca-certificates \
		curl \
		bzip2 \
		gcc \
		libapr1-dev \
		libaprutil1-dev \
		libc6-dev \
		libpcre++-dev \
		libssl-dev \
		make \
	' \
	set -x \
	&& apt-get update \
	&& apt-get install -y --no-install-recommends $buildDeps \
	&& rm -r /var/lib/apt/lists/* \
	&& curl -SL "$HTTPD_BZ2_URL" -o httpd.tar.bz2 \
	&& curl -SL "$HTTPD_BZ2_URL.asc" -o httpd.tar.bz2.asc \
	&& gpg --verify httpd.tar.bz2.asc \
	&& mkdir -p src/httpd \
	&& tar -xvf httpd.tar.bz2 -C src/httpd --strip-components=1 \
	&& rm httpd.tar.bz2* \
	&& cd src/httpd \
	&& ./configure --enable-so --enable-ssl --prefix=$HTTPD_PREFIX \
	&& make -j"$(nproc)" \
	&& make install \
	&& cd ../../ \
	&& rm -r src/httpd \
	&& sed -ri ' \
		s!^(\s*CustomLog)\s+\S+!\1 /proc/self/fd/1!g; \
		s!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g; \
		' /usr/local/apache2/conf/httpd.conf \
	&& apt-get purge -y --auto-remove $buildDeps

COPY httpd-foreground /usr/local/bin/

EXPOSE 80
CMD ["httpd-foreground"]
```

###プロキシで制限ある場合

そのままdocker buildすると以下のようなメッセージが出ます

```bash
Step 6 : RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B1B96F45DFBDCCF974019235193F180AB55D9977
 ---> Running in c49c0ae021f2
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: requesting key B55D9977 from hkp server ha.pool.sks-keyservers.net
gpg: keyserver timed out
gpg: keyserver receive failed: keyserver error
INFO[0127] The command [/bin/sh -c gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B1B96F45DFBDCCF974019235193F180AB55D9977] returned a non-zero code: 2

とか

+ rm -r /var/lib/apt/lists/httpredir.debian.org_debian_dists_jessie-updates_InRelease /var/lib/apt/lists/httpredir.debian.org_debian_dists_jessie-updates_main_binary-amd64_Packages.gz /var/lib/apt/lists/httpredir.debian.org_debian_dists_jessie_InRelease /var/lib/apt/lists/httpredir.debian.org_debian_dists_jessie_main_binary-amd64_Packages.gz /var/lib/apt/lists/lock /var/lib/apt/lists/partial /var/lib/apt/lists/security.debian.org_dists_jessie_updates_InRelease /var/lib/apt/lists/security.debian.org_dists_jessie_updates_main_binary-amd64_Packages.gz
+ curl -SL https://www.apache.org/dist/httpd/httpd-2.2.29.tar.bz2 -o httpd.tar.bz2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:04:14 --:--:--     0curl: (7) Failed to connect to www.apache.org port 443: Connection timed out
```


以下の設定を変更しましょう

```bash
-RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B1B96F45DFBDCCF974019235193F180AB55D9977

+RUN gpg --keyserver ha.pool.sks-keyservers.net --keyserver-option http-proxy=http://アカウント名:パスワード@アドレス:ポート --recv-keys B1B96F45DFBDCCF974019235193F180AB55D9977




-&& curl -SL "$HTTPD_BZ2_URL" -o httpd.tar.bz2 \
-&& curl -SL "$HTTPD_BZ2_URL.asc" -o httpd.tar.bz2.asc \

+&& curl -U アカウント名:パスワード -x アドレス:ポート -SL "$HTTPD_BZ2_URL" -o httpd.tar.bz2 \
+&& curl -U アカウント名:パスワード -x アドレス:ポート -SL "$HTTPD_BZ2_URL.asc" -o httpd.tar.bz2.asc \
```


※パスワードに特殊記号を使用している場合はURLエンコードする必要があります


##httpd-foregroundの作成

```bash
vi httpd-foreground
chmod a+x httpd-foreground
```

以下の内容をまるごと貼り付けて下さい。
https://github.com/docker-library/httpd/blob/63cd0ad57a12c76ff70d0f501f6c2f1580fa40f5/2.2/httpd-foreground


```bash
#!/bin/bash
set -e

# Apache gets grumpy about PID files pre-existing
rm -f /usr/local/apache2/logs/httpd.pid

exec httpd -DFOREGROUND
```

##docker buildの実行

```bash
docker build --force-rm=true --rm=true -t apache:2.2.9 .
```

##dockerコンテナ起動
```bash
docker run-d -p 80 apache:2.2.9
```


おわり！