开发者社区> 问答> 正文

Docker 怎么安装Apache啊?

已解决

Docker 怎么安装Apache啊?

展开
收起
格格的阿里云 2022-04-03 10:09:09 790 0
1 条回答
写回答
取消 提交回答
  • 推荐回答

    方法一、docker pull httpd
    查看 Docker Hub 上的 httpd 镜像:

    能使用 Sort by 寻找其他版本的 httpd,一般为最新版本 httpd:latest。

    也能够通过 docker search httpd 命令来寻找支持的版本:

    先拉取官方的镜像

    runoob@runoob:~/apache$ docker pull httpd
    

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

    方法二、通过 Dockerfile 构建
    创建 Dockerfile

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

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

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

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

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

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

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

     #!/bin/bash
    set -e
    
    # Apache gets grumpy about PID files pre-existing
    rm -f /usr/local/apache2/logs/httpd.pid
    
    exec httpd -DFOREGROUND
    

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

    runoob@runoob:~/apache$ chmod +x httpd-foreground
    

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

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

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

    runoob@runoob:~/apache$ docker images httpd
    REPOSITORY     TAG        IMAGE ID        CREATED           SIZE
    httpd          latest     da1536b4ef14    23 seconds ago    195.1 MB
    
    
    2022-04-03 11:11:01
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Apache Flink技术进阶 立即下载
Apache Spark: Cloud and On-Prem 立即下载
Hybrid Cloud and Apache Spark 立即下载