ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

二十三、Spring Cloud+Spring Boot+Mybatis+ElementUI 实现前后端之 Docker 安装 Apache

2021-12-09 15:00:48  阅读:160  来源: 互联网

标签:httpd OK conf ElementUI Spring xxx Boot && apache


Docker 安装 Apache


方法一、docker pull httpd

查找   上的 httpd 镜像:

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

推荐分布式架构源码

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

xxx@xxx:~/apache$ docker search httpd
NAME                           DESCRIPTION                  STARS  OFFICIAL AUTOMATED
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的镜像。

xxx@xxx:~/apache$ docker images httpd
REPOSITORY     TAG        IMAGE ID        CREATED           SIZE
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。

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
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# \
    && apt-get install -y --no-install-recommends \
        libapr1 \
        libaprutil1 \
        libaprutil1-ldap \
        libapr1-dev \
        libaprutil1-dev \
        libpcre++0 \
        libssl1.0.0 \
    && rm -r /var/lib/apt/lists/*
ENV HTTPD_VERSION 2.4.20
ENV HTTPD_BZ2_URL 
RUN buildDeps=' \
        ca-certificates \
        curl \
        bzip2 \
        gcc \
        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 -fSL "$HTTPD_BZ2_URL" -o httpd.tar.bz2 \
    && curl -fSL "$HTTPD_BZ2_URL.asc" -o httpd.tar.bz2.asc \
# see 
    && export GNUPGHOME="$(mktemp -d)" \
    && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys A93D62ECC3C8EA12DB220EC934EA76E6791485A8 \
    && gpg --batch --verify httpd.tar.bz2.asc httpd.tar.bz2 \
    && rm -r "$GNUPGHOME" httpd.tar.bz2.asc \
    \
    && mkdir -p src \
    && tar -xvf httpd.tar.bz2 -C src --strip-components=1 \
    && rm httpd.tar.bz2 \
    && cd src \
    \
    && ./configure \
        --prefix="$HTTPD_PREFIX" \
        --enable-mods-shared=reallyall \
    && make -j"$(nproc)" \
    && make install \
    \
    && cd .. \
    && rm -r src \
    \
    && sed -ri \
        -e 's!^(\s*CustomLog)\s+\S+!\1 /proc/self/fd/1!g' \
        -e 's!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g' \
        "$HTTPD_PREFIX/conf/httpd.conf" \
    \
    && apt-get purge -y --auto-remove $buildDeps
COPY httpd-foreground /usr/local/bin/
EXPOSE 80
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:~/apache$ chmod +x httpd-foreground

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

xxx@xxx:~/apache$ docker build -t httpd .

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

xxx@xxx:~/apache$ docker images httpd
REPOSITORY     TAG        IMAGE ID        CREATED           SIZE
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/。

查看容器启动情况:

xxx@xxx:~/apache$ docker ps
CONTAINER ID  IMAGE   COMMAND             ... PORTS               NAMES79a97f2aac37  httpd   "httpd-foreground"  ... 0.0.0.0:80->80/tcp  sharp_swanson

通过浏览器访问

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

标签:httpd,OK,conf,ElementUI,Spring,xxx,Boot,&&,apache
来源: https://blog.csdn.net/m0_46413639/article/details/121616060

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有