LoginSignup
4
3

More than 3 years have passed since last update.

alpine版のhttpdイメージは大きすぎて使い物にならない

Last updated at Posted at 2020-06-15

httpd:alpine はでかすぎる!

Docker の Alpine Linux 公式イメージ は 5.57MB しかないのに、Alpine Linux ベースの httpd 公式イメージは 107MB もあります。でかい!

これは mod_perl のような httpd モジュールをビルドをできるよう、依存しているパッケージをまるごと追加しているからです。……が、まるごとすぎて思わず呻いてしまいます。

.httpd-rundeps-20200424.154745 noarch {.httpd-rundeps} () [installed]
alpine-baselayout-3.2.0-r3 x86_64 {alpine-baselayout} (GPL-2.0-only) [installed]
alpine-keys-2.1-r2 x86_64 {alpine-keys} (MIT) [installed]
apk-tools-2.10.5-r0 x86_64 {apk-tools} (GPL2) [installed]
apr-1.7.0-r0 x86_64 {apr} (Apache-2.0) [installed]
apr-dev-1.7.0-r0 x86_64 {apr} (Apache-2.0) [installed]
apr-util-1.6.1-r6 x86_64 {apr-util} (Apache-2.0) [installed]
apr-util-dbm_db-1.6.1-r6 x86_64 {apr-util} (Apache-2.0) [installed]
apr-util-dev-1.6.1-r6 x86_64 {apr-util} (Apache-2.0) [installed]
apr-util-ldap-1.6.1-r6 x86_64 {apr-util} (Apache-2.0) [installed]
bash-5.0.11-r1 x86_64 {bash} (GPL-3.0-or-later) [installed]
brotli-1.0.7-r3 x86_64 {brotli} (MIT) [installed]
busybox-1.31.1-r9 x86_64 {busybox} (GPL-2.0-only) [installed]
ca-certificates-20191127-r1 x86_64 {ca-certificates} (MPL-2.0 GPL-2.0-or-later) [installed]
ca-certificates-cacert-20191127-r1 x86_64 {ca-certificates} (MPL-2.0 GPL-2.0-or-later) [installed]
cyrus-sasl-dev-2.1.27-r5 x86_64 {cyrus-sasl} (custom) [installed]
db-5.3.28-r1 x86_64 {db} (custom) [installed]
db-c++-5.3.28-r1 x86_64 {db} (custom) [installed]
db-dev-5.3.28-r1 x86_64 {db} (custom) [installed]
expat-2.2.9-r1 x86_64 {expat} (MIT) [installed]
expat-dev-2.2.9-r1 x86_64 {expat} (MIT) [installed]
jansson-2.12-r0 x86_64 {jansson} (MIT) [installed]
libaio-0.3.112-r1 x86_64 {libaio} (LGPL-2.1-or-later) [installed]
libblkid-2.34-r1 x86_64 {util-linux} (GPL-2.0 GPL-2.0-or-later LGPL-2.0-or-later BSD Public-Domain) [installed]
libbz2-1.0.8-r1 x86_64 {bzip2} (bzip2-1.0.6) [installed]
libc-utils-0.7.2-r0 x86_64 {libc-dev} (BSD) [installed]
libcrypto1.1-1.1.1g-r0 x86_64 {openssl} (OpenSSL) [installed]
libcurl-7.67.0-r0 x86_64 {curl} (MIT) [installed]
libfdisk-2.34-r1 x86_64 {util-linux} (GPL-2.0 GPL-2.0-or-later LGPL-2.0-or-later BSD Public-Domain) [installed]
libgcc-9.2.0-r4 x86_64 {gcc} (GPL LGPL) [installed]
libldap-2.4.48-r1 x86_64 {openldap} (custom) [installed]
libmount-2.34-r1 x86_64 {util-linux} (GPL-2.0 GPL-2.0-or-later LGPL-2.0-or-later BSD Public-Domain) [installed]
libpq-12.2-r0 x86_64 {postgresql} (PostgreSQL) [installed]
libsasl-2.1.27-r5 x86_64 {cyrus-sasl} (custom) [installed]
libsmartcols-2.34-r1 x86_64 {util-linux} (GPL-2.0 GPL-2.0-or-later LGPL-2.0-or-later BSD Public-Domain) [installed]
libssl1.1-1.1.1g-r0 x86_64 {openssl} (OpenSSL) [installed]
libstdc++-9.2.0-r4 x86_64 {gcc} (GPL LGPL) [installed]
libtls-standalone-2.9.1-r0 x86_64 {libtls-standalone} (ISC) [installed]
libuuid-2.34-r1 x86_64 {util-linux} (GPL-2.0 GPL-2.0-or-later LGPL-2.0-or-later BSD Public-Domain) [installed]
libxml2-2.9.10-r2 x86_64 {libxml2} (MIT) [installed]
lua5.1-libs-5.1.5-r7 x86_64 {lua5.1} (MIT) [installed]
mariadb-common-10.4.12-r0 x86_64 {mariadb} (GPL-2.0-or-later) [installed]
mariadb-connector-c-3.1.6-r0 x86_64 {mariadb-connector-c} (LGPL-2.1-or-later) [installed]
mariadb-connector-c-dev-3.1.6-r0 x86_64 {mariadb-connector-c} (LGPL-2.1-or-later) [installed]
mariadb-dev-10.4.12-r0 x86_64 {mariadb} (GPL-2.0-or-later) [installed]
mariadb-embedded-10.4.12-r0 x86_64 {mariadb} (GPL-2.0-or-later) [installed]
musl-1.1.24-r2 x86_64 {musl} (MIT) [installed]
musl-utils-1.1.24-r2 x86_64 {musl} (MIT BSD GPL2+) [installed]
ncurses-libs-6.1_p20200118-r3 x86_64 {ncurses} (MIT) [installed]
ncurses-terminfo-base-6.1_p20200118-r3 x86_64 {ncurses} (MIT) [installed]
nghttp2-libs-1.40.0-r0 x86_64 {nghttp2} (MIT) [installed]
openldap-dev-2.4.48-r1 x86_64 {openldap} (custom) [installed]
openssl-dev-1.1.1g-r0 x86_64 {openssl} (OpenSSL) [installed]
pcre-8.43-r0 x86_64 {pcre} (BSD-3-Clause) [installed]
perl-5.30.1-r0 x86_64 {perl} (Artistic GPL-2.0) [installed]
pkgconf-1.6.3-r0 x86_64 {pkgconf} (ISC) [installed]
postgresql-dev-12.2-r0 x86_64 {postgresql} (PostgreSQL) [installed]
postgresql-libs-12.2-r0 x86_64 {postgresql} (PostgreSQL) [installed]
readline-8.0.1-r0 x86_64 {readline} (GPL-2.0-or-later) [installed]
scanelf-1.2.4-r0 x86_64 {pax-utils} (GPL-2.0-only) [installed]
sqlite-dev-3.30.1-r1 x86_64 {sqlite} (Public-Domain) [installed]
sqlite-libs-3.30.1-r1 x86_64 {sqlite} (Public-Domain) [installed]
ssl_client-1.31.1-r9 x86_64 {busybox} (GPL-2.0-only) [installed]
util-linux-dev-2.34-r1 x86_64 {util-linux} (GPL-2.0 GPL-2.0-or-later LGPL-2.0-or-later BSD Public-Domain) [installed]
xz-libs-5.2.4-r0 x86_64 {xz} (GPL-2.0-or-later Public-Domain) [installed]
zlib-1.2.11-r3 x86_64 {zlib} (Zlib) [installed]
zlib-dev-1.2.11-r3 x86_64 {zlib} (Zlib) [installed]

httpd モジュールをビルドするだけなのに mariadb や postgres のライブラリはいらんでしょう……?

こんなことになってしまっている理由ははっきりしています。モジュールのビルドに使う APR Util のパッケージの作りが雑なのです。

build() {
    cd "$builddir"
    ./configure \
        --build=$CBUILD \
        --host=$CHOST \
        --prefix=/usr \
        --with-apr=/usr \
        --with-ldap \
        --with-dbm=db53 \
        --with-pgsql \
        --with-mysql \
        --with-sqlite3 \
        --with-berkeley-db \
        --with-crypto \
        --with-openssl \
        --without-sqlite2 \
        --without-gdbm
    make
}

分けるの面倒だから全部まとめちゃえ! というメンテナの声が聞こえますね。

APR Util がサポートするすべての機能をオンにすればどんなモジュールもビルドできるはずなので、これも一つのやり方かもしれません。しかし、さすがにひどい。

alpine の apache2 パッケージを使う

特殊なモジュールを使わず、ビルドもせず、ただ普通に httpd を使いたいだけなら、httpd:alpine イメージを使うのではなく、alpine イメージに apache2 パッケージを入れた方が断然いいです。

ベースパッケージは apache2 です。これで普通の HTTP サーバとして動作します。

apk add apache2

それに加えて HTTPS や HTTP/2 へ対応させたい場合は、

apk add apache2-ssl
apk add apache2-http2

でOKです。めっちゃ簡単!

apache2パッケージ定義はここにあります。Lua や Proxy, WebDAV などにも対応できますよ。
あと、これ以外にも mod_wsgi もありました。

HTTPS, HTTP/2 のパッケージを入れた状態でイメージ化したところ 12.3MB と、コンパクトにまとまりました。よかったよかった。

(追補) mod_perl を build する

格好よくないですが、いったん apache2-dev を導入して、build したあとで削除することで導入できます。最低限の確認しかしていませんが、たぶん動きます。

apk add gcc make apache2-dev libc-dev perl-dev
perl Makefile.PL
make
make install
apk del gcc make apache2-dev libc-dev perl-dev
apk add perl
4
3
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
3