Open6

DockerでApacheのソースコードをビルドして実行する

tommy34tommy34

Dockerfile

FROM ubuntu:24.04

ENV TZ=Asia/Tokyo
ENV PATH $PATH:/usr/local/nginx/sbin
ENV APR_UTIL_VERSION 1.6.3
ENV APR_VERSION 1.7.4
ENV APACHE_VERSION 2.4.58

RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone && \
  sed -i 's@archive.ubuntu.com@ftp.jaist.ac.jp/pub/Linux@g' /etc/apt/sources.list && \
  echo "bind 'set bell-style none'" >> .bashrc && \
  apt-get update && apt-get install --no-install-recommends -y wget build-essential libpcre3-dev libexpat-dev curl cloc && \
  apt-get clean && \
  rm -rf /var/lib/apt/lists/* && \
  wget -q --no-check-certificate https://dlcdn.apache.org//apr/apr-util-${APR_UTIL_VERSION}.tar.gz && \
  tar xf apr-util-${APR_UTIL_VERSION}.tar.gz && \
  wget -q --no-check-certificate https://dlcdn.apache.org//apr/apr-${APR_VERSION}.tar.gz && \
  tar xf apr-${APR_VERSION}.tar.gz && \
  wget -q --no-check-certificate https://dlcdn.apache.org/httpd/httpd-${APACHE_VERSION}.tar.gz && \
  tar xf httpd-${APACHE_VERSION}.tar.gz

WORKDIR /apr-${APR_VERSION}

RUN ./configure && make install

WORKDIR /apr-util-${APR_UTIL_VERSION}

RUN ./configure --with-apr=/apr-${APR_VERSION} && make -j"$(nproc)" install

WORKDIR /httpd-${APACHE_VERSION}

RUN ./configure && make -j$(nproc) install
tommy34tommy34

コンテナのビルド

$ docker build -t apache_build .
[+] Building 59.2s (12/12) FINISHED                                                                                                                                                   docker:desktop-linux
 => [internal] load .dockerignore                                                                                                                                                                     0.1s
 => => transferring context: 2B                                                                                                                                                                       0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                  0.1s
 => => transferring dockerfile: 1.32kB                                                                                                                                                                0.0s
 => [internal] load metadata for docker.io/library/ubuntu:24.04                                                                                                                                       1.0s
 => [1/8] FROM docker.io/library/ubuntu:24.04@sha256:36fa0c7153804946e17ee951fdeffa6a1c67e5088438e5b90de077de5c600d4c                                                                                 0.0s
 => CACHED [2/8] RUN ln -snf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && echo Asia/Tokyo > /etc/timezone &&   sed -i 's@archive.ubuntu.com@ftp.jaist.ac.jp/pub/Linux@g' /etc/apt/sources.list &  0.0s
 => CACHED [3/8] WORKDIR /apr-1.7.4                                                                                                                                                                   0.0s
 => CACHED [4/8] RUN ./configure && make install                                                                                                                                                      0.0s
 => CACHED [5/8] WORKDIR /apr-util-1.6.3                                                                                                                                                              0.0s
 => [6/8] RUN ./configure --with-apr=/apr-1.7.4 && make -j"$(nproc)" install                                                                                                                          8.4s
 => [7/8] WORKDIR /httpd-2.4.58                                                                                                                                                                       0.0s
 => [8/8] RUN ./configure && make -j"$(nproc)" install                                                                                                                                               48.0s
 => exporting to image                                                                                                                                                                                1.7s
 => => exporting layers                                                                                                                                                                               1.7s
 => => writing image sha256:64bddb2e1f7ca9cf57c07b8cf676c917ada258f523cdd34e111754c9c5dbd011                                                                                                          0.0s
 => => naming to docker.io/library/apache_build                                                                                                                                                       0.0s

What's Next?
  View a summary of image vulnerabilities and recommendations → docker scout quickview
tommy34tommy34

コンテナでApacheが動作することが確認できる

$ docker run -it --rm --name apache_build_container apache_build bash
root@37f4f6a2983e:/httpd-2.4.58# /usr/local/apache2/bin/httpd -V
Server version: Apache/2.4.58 (Unix)
Server built:   Feb 12 2024 01:57:33
Server's Module Magic Number: 20120211:129
Server loaded:  APR 1.7.4, APR-UTIL 1.6.3, PCRE 8.39 2016-06-14
Compiled using: APR 1.7.4, APR-UTIL 1.6.3, PCRE 8.39 2016-06-14
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_PROC_PTHREAD_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/usr/local/apache2"
 -D SUEXEC_BIN="/usr/local/apache2/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"
root@37f4f6a2983e:/httpd-2.4.58# /usr/local/apache2/bin/httpd -h
Usage: /usr/local/apache2/bin/httpd [-D name] [-d directory] [-f file]
                                    [-C "directive"] [-c "directive"]
                                    [-k start|restart|graceful|graceful-stop|stop]
                                    [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
Options:
  -D name            : define a name for use in <IfDefine name> directives
  -d directory       : specify an alternate initial ServerRoot
  -f file            : specify an alternate ServerConfigFile
  -C "directive"     : process directive before reading config files
  -c "directive"     : process directive after reading config files
  -e level           : show startup errors of level (see LogLevel)
  -E file            : log startup errors to file
  -v                 : show version number
  -V                 : show compile settings
  -h                 : list available command line options (this page)
  -l                 : list compiled in modules
  -L                 : list available configuration directives
  -t -D DUMP_VHOSTS  : show parsed vhost settings
  -t -D DUMP_RUN_CFG : show parsed run settings
  -S                 : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
  -t -D DUMP_MODULES : show all loaded modules
  -M                 : a synonym for -t -D DUMP_MODULES
  -t -D DUMP_INCLUDES: show all included configuration files
  -t                 : run syntax check for config files
  -T                 : start without DocumentRoot(s) check
  -X                 : debug mode (only one worker, do not detach)
root@37f4f6a2983e:/httpd-2.4.58# ps aufx
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.1  0.0   4204  3328 pts/0    Ss   01:58   0:00 bash
root        11 50.0  0.0   7488  3328 pts/0    R+   01:58   0:00 ps aufx
root@37f4f6a2983e:/httpd-2.4.58# /usr/local/apache2/bin/httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
root@37f4f6a2983e:/httpd-2.4.58# ps aufx
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   4204  3328 pts/0    Ss   01:58   0:00 bash
root        13  0.0  0.0   8120  3696 ?        Ss   01:59   0:00 /usr/local/apache2/bin/httpd
daemon      14  0.0  0.0 2000700 3828 ?        Sl   01:59   0:00  \_ /usr/local/apache2/bin/httpd
daemon      15  0.0  0.0 2000700 3828 ?        Sl   01:59   0:00  \_ /usr/local/apache2/bin/httpd
daemon      17  0.0  0.0 2000700 3828 ?        Sl   01:59   0:00  \_ /usr/local/apache2/bin/httpd
root        98  0.0  0.0   7488  3328 pts/0    R+   01:59   0:00 ps aufx
root@37f4f6a2983e:/httpd-2.4.58# curl localhost
<html><body><h1>It works!</h1></body></html>
tommy34tommy34

ソースコードの行数は約57万行

root@37f4f6a2983e:/httpd-2.4.58# ls
ABOUT_APACHE     CHANGES         LICENSE       NWGNUmakefile     ROADMAP          build            config.log     docs         httpd.mak     libhttpd.mak  os
Apache-apr2.dsw  CMakeLists.txt  Makefile      README            VERSIONING       buildconf        config.nice    emacs-style  httpd.spec    modules       server
Apache.dsw       INSTALL         Makefile.in   README.CHANGES    acinclude.m4     buildmark.o      config.status  httpd        include       modules.c     srclib
BuildAll.dsp     InstallBin.dsp  Makefile.win  README.cmake      ap.d             changes-entries  configure      httpd.dep    libhttpd.dep  modules.lo    support
BuildBin.dsp     LAYOUT          NOTICE        README.platforms  apache_probes.d  config.layout    configure.in   httpd.dsp    libhttpd.dsp  modules.o     test
root@37f4f6a2983e:/httpd-2.4.58# cloc .
    3382 text files.
    2018 unique files.
    2114 files ignored.

github.com/AlDanial/cloc v 1.98  T=2.17 s (931.6 files/s, 347297.3 lines/s)
---------------------------------------------------------------------------------------
Language                             files          blank        comment           code
---------------------------------------------------------------------------------------
XML                                    833          39545          19756         262737
C                                      328          34703          42640         205290
Bourne Shell                            26           7216           4523          48588
C/C++ Header                           188           4656          18359          13313
Python                                 128           2052           2053          13246
SVG                                      1              1              1           5877
HTML                                   261            881             10           3678
m4                                      53            461            689           3506
Lua                                     12            311            132           1924
Perl                                    13            320            570           1505
CSS                                      8            334            355           1447
make                                    71            184            244           1440
Bourne Again Shell                       3            117            211           1315
JavaScript                               3            116            556           1104
CMake                                    2            165            115           1093
Expect                                  36              0              1            849
awk                                      7             86            111            749
D                                        2              7              9            308
lex                                      1             43             64            293
Korn Shell                               3             50             70            286
Text                                     6             73              0            256
YAML                                     1              4             58            227
DTD                                      6            118            121            185
yacc                                     1             34             22            161
Windows Resource File                    2             17             31            143
DAL                                      1              1              3            117
IDL                                      2              0              0            112
JSON                                    14              2              0             90
INI                                      1              4              0             28
Markdown                                 1             12              0             28
TeX                                      1              9             45             26
Properties                               1              5              5             17
Visual Basic Script                      1              5             13             14
Windows Module Definition                1              4              3             12
---------------------------------------------------------------------------------------
SUM:                                  2018          91536          90770         569964
---------------------------------------------------------------------------------------