• [第二十三篇]——Docker 安装 Apache之SpringCloud大型企业分布式微服务云架构源码


    Docker 安装 Apache


    方法一、docker pull httpd

    查找   上的 httpd 镜像:

    可以通过 Sort by 查看其他版本的 httpd,默认是最新版本 httpd:latest

    推荐分布式架构源码

    此外,我们还可以用 docker search httpd 命令来查看可用版本:

    1. xxx@xxx:~/apache$ docker search httpd
    2. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
    3. httpd The Apache HTTP Server .. 524 [OK] centos/httpd 7 [OK]rgielen/httpd-image-php5 Docker image for Apache... 1 [OK]microwebapps/httpd-frontend Httpd frontend allowing... 1 [OK]lolhens/httpd Apache httpd 2 Server 1 [OK]publici/httpd httpd:latest 0 [OK]publicisworldwide/httpd The Apache httpd webser... 0 [OK]rgielen/httpd-image-simple Docker image for simple... 0 [OK]solsson/httpd Derivatives of the offi... 0 [OK]rgielen/httpd-image-drush Apache HTTPD + Drupal S... 0 [OK]learninglayers/httpd 0 [OK]sohrabkhan/httpd Docker httpd + php5.6 (... 0 [OK]aintohvri/docker-httpd Apache HTTPD Docker ext... 0 [OK]alizarion/httpd httpd on centos with mo... 0 [OK]...

    这里我们拉取官方的镜像

    xxx@xxx:~/apache$ docker pull httpd

    等待下载完成后,我们就可以在本地镜像列表里查到REPOSITORY为httpd的镜像。

    1. xxx@xxx:~/apache$ docker images httpd
    2. REPOSITORY TAG IMAGE ID CREATED SIZE
    3. httpd latest da1536b4ef14 23 seconds ago 195.1 MB

    方法二、通过 Dockerfile 构建

    创建 Dockerfile

    首先,创建目录apache,用于存放后面的相关东西。

    xxx@xxx:~$ mkdir -p  ~/apache/www ~/apache/logs ~/apache/conf

    www 目录将映射为 apache 容器配置的应用程序目录。

    logs 目录将映射为 apache 容器的日志目录。

    conf 目录里的配置文件将映射为 apache 容器的配置文件。

    进入创建的 apache 目录,创建 Dockerfile。

    1. 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-dataENV HTTPD_PREFIX /usr/local/apache2
    2. ENV PATH $PATH:$HTTPD_PREFIX/bin
    3. RUN mkdir -p "$HTTPD_PREFIX" \
    4. && chown www-data:www-data "$HTTPD_PREFIX"WORKDIR $HTTPD_PREFIX# install httpd runtime dependencies# \
    5. && apt-get install -y --no-install-recommends \
    6. libapr1 \
    7. libaprutil1 \
    8. libaprutil1-ldap \
    9. libapr1-dev \
    10. libaprutil1-dev \
    11. libpcre++0 \
    12. libssl1.0.0 \
    13. && rm -r /var/lib/apt/lists/*
    14. ENV HTTPD_VERSION 2.4.20
    15. ENV HTTPD_BZ2_URL
    16. RUN buildDeps=' \
    17. ca-certificates \
    18. curl \
    19. bzip2 \
    20. gcc \
    21. libpcre++-dev \
    22. libssl-dev \
    23. make \
    24. ' \
    25. set -x \
    26. && apt-get update \
    27. && apt-get install -y --no-install-recommends $buildDeps \
    28. && rm -r /var/lib/apt/lists/* \
    29. \
    30. && curl -fSL "$HTTPD_BZ2_URL" -o httpd.tar.bz2 \
    31. && curl -fSL "$HTTPD_BZ2_URL.asc" -o httpd.tar.bz2.asc \
    32. # see
    33. && export GNUPGHOME="$(mktemp -d)" \
    34. && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys A93D62ECC3C8EA12DB220EC934EA76E6791485A8 \
    35. && gpg --batch --verify httpd.tar.bz2.asc httpd.tar.bz2 \
    36. && rm -r "$GNUPGHOME" httpd.tar.bz2.asc \
    37. \
    38. && mkdir -p src \
    39. && tar -xvf httpd.tar.bz2 -C src --strip-components=1 \
    40. && rm httpd.tar.bz2 \
    41. && cd src \
    42. \
    43. && ./configure \
    44. --prefix="$HTTPD_PREFIX" \
    45. --enable-mods-shared=reallyall \
    46. && make -j"$(nproc)" \
    47. && make install \
    48. \
    49. && cd .. \
    50. && rm -r src \
    51. \
    52. && sed -ri \
    53. -e 's!^(\s*CustomLog)\s+\S+!\1 /proc/self/fd/1!g' \
    54. -e 's!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g' \
    55. "$HTTPD_PREFIX/conf/httpd.conf" \
    56. \
    57. && apt-get purge -y --auto-remove $buildDeps
    58. COPY httpd-foreground /usr/local/bin/
    59. EXPOSE 80
    60. CMD ["httpd-foreground"]

    Dockerfile文件中 COPY httpd-foreground /usr/local/bin/ 是将当前目录下的httpd-foreground拷贝到镜像里,作为httpd服务的启动脚本,所以我们要在本地创建一个脚本文件httpd-foreground

    #!/bin/bashset -e# Apache gets grumpy about PID files pre-existingrm -f /usr/local/apache2/logs/httpd.pidexec httpd -DFOREGROUND

    赋予 httpd-foreground 文件可执行权限。

    xxx@xxx:~/apachechmod +x httpd-foreground

    通过 Dockerfile 创建一个镜像,替换成你自己的名字。

    xxx@xxx:~/apachedocker build -t httpd .

    创建完成后,我们可以在本地的镜像列表里查找到刚刚创建的镜像。

    1. xxx@xxx:~/apachedocker images httpd
    2. REPOSITORY     TAG        IMAGE ID        CREATED           SIZE
    3. httpd          latest     da1536b4ef14    23 seconds ago    195.1 MB

    使用 apache 镜像

    运行容器

    docker run -p 80:80 -v $PWD/www/:/usr/local/apache2/htdocs/ -v $PWD/conf/httpd.conf:/usr/local/apache2/conf/httpd.conf -v $PWD/logs/:/usr/local/apache2/logs/ -d httpd

    命令说明:

    -p 80:80: 将容器的 80 端口映射到主机的 80 端口。

    -v $PWD/www/:/usr/local/apache2/htdocs/: 将主机中当前目录下的 www 目录挂载到容器的 /usr/local/apache2/htdocs/。

    -v $PWD/conf/httpd.conf:/usr/local/apache2/conf/httpd.conf: 将主机中当前目录下的 conf/httpd.conf 文件挂载到容器的 /usr/local/apache2/conf/httpd.conf。

    -v $PWD/logs/:/usr/local/apache2/logs/: 将主机中当前目录下的 logs 目录挂载到容器的 /usr/local/apache2/logs/。

    查看容器启动情况:

    1. xxx@xxx:~/apachedocker ps
    2. CONTAINER ID  IMAGE   COMMAND             ... PORTS               NAMES79a97f2aac37  httpd   "httpd-foreground"  ... 0.0.0.0:80->80/tcp  sharp_swanson

    通过浏览器访问

    需要框架源码请看我个人简介 

  • 相关阅读:
    「项目实战」一文读懂思科网络设备IOS系统
    【前端技术】CSS基础入门篇
    全志H616开发版
    25. K 个一组翻转链表
    技术干货 | GreatDB新一代读写分离架构,如何炼就近乎0损耗的性能?
    LeetCode 131 Java 实现
    EIVideo的安装笔记
    每天五分钟机器学习:数据和特征决定机器学习的上限(特征工程)
    内存泄露的最直接表现
    练[MRCTF2020]Ez_bypass
  • 原文地址:https://blog.csdn.net/m0_66404702/article/details/125410893