Docker 用centos 编译安装apache

Docker 用centos 编译安装apache

前提条件: 安装docker

如果想安装docker请查阅:安装docker

环境准备:centos8

  1. 拉取centos镜像

    [root@lvs docker]# docker pull centos:8
    8: Pulling from library/centos
    a1d0c7532777: Pull complete
    Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
    Status: Downloaded newer image for centos:8
    docker.io/library/centos:8
    [root@lvs docker]# docker images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    centos 8 5d0da3dc9764 2 years ago 231MB

    [root@lvs ~]# docker run --name ttq6 -it centos
    Unable to find image 'centos:latest' locally
    latest: Pulling from library/centos
    Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
    Status: Downloaded newer image for centos:latest
    [root@ce7828597669 /]# ls
    bin etc lib lost+found mnt proc run srv tmp var
    dev home lib64 media opt root sbin sys usr
    [root@ce7828597669 /]#

    1. 进入容器操作

    编译安装apache

    [root@ce7828597669 ~]# cd /etc/yum.repos.d/
    [root@ce7828597669 yum.repos.d]# rm -rf *
    [root@ce7828597669 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
    [root@ce7828597669 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
    [root@ce7828597669 yum.repos.d]# yum clean all
    [root@ce7828597669 yum.repos.d]# yum makecache
    [root@ce7828597669 ~]# groupadd -r apache
    [root@ce7828597669 ~]# useradd -r -M -s /sbin/nologin -g apache apache
    [root@ce7828597669 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
    [root@ce7828597669 ~]# yum -y install gcc gcc-c++
    [root@ce7828597669 src]# wget https://downloads.apache.org/apr/apr-1.7.4.tar.gz
    [root@ce7828597669 src]# wget https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz
    [root@ce7828597669 src]# wget http://archive.apache.org/dist/httpd/httpd-2.4.57.tar.gz
    [root@ce7828597669 src]# ls
    apr-1.7.4.tar.gz apr-util-1.6.3.tar.gz debug httpd-2.4.57.tar.gz kernels
    [root@ce7828597669 src]# tar xf apr-1.7.4.tar.gz
    [root@ce7828597669 src]# tar xf apr-util-1.6.3.tar.gz
    [root@ce7828597669 src]# tar xf httpd-2.4.57.tar.gz
    [root@ce7828597669 src]# ls
    apr-1.7.4 apr-util-1.6.3 debug httpd-2.4.57.tar.gz
    apr-1.7.4.tar.gz apr-util-1.6.3.tar.gz httpd-2.4.57 kernels
    [root@ce7828597669 src]# cd apr-1.7.4
    [root@ce7828597669 apr-1.7.4]# sed -i '/RM "cfgfile"/d' configure
    [root@ce7828597669 apr-1.7.4]# ./configure --prefix=/usr/local/apr
    [root@ce7828597669 apr-1.7.4]# make && make install
    [root@ce7828597669 src]# cd apr-util-1.6.3
    [root@ce7828597669 apr-util-1.6.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    [root@ce7828597669 apr-util-1.6.3]# make && make install

    [root@ce7828597669 httpd-2.4.57]# cd httpd-2.4.57
    ./configure --prefix=/usr/local/apache --sysco-with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

    [root@ce7828597669 httpd-2.4.57]# make && make install
    [root@ce7828597669 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
    [root@ce7828597669 ~]# source /etc/profile.d/httpd.sh
    [root@ce7828597669 ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
    [root@ce7828597669 ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
    [root@ce7828597669 ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
    [root@ce7828597669 ~]# apachectl start
    [root@ce7828597669 ~]# ss -antl
    State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
    LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
    [root@lvs ~]# curl 172.17.0.2

    It works!

    [root@lvs ~]# [root@lvs ~]# docker commit -p ttq6 //创建 sha256:ac2cf0f87374d4726a2e7b3631fbe0af711c965fcdeb3e2ec4c52cbd90d25fdd [root@lvs ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ac2cf0f87374 15 seconds ago 745MB httpd latest 7f6a969e81a5 31 hours ago 168MB centos 8 5d0da3dc9764 2 years ago 231MB centos latest 5d0da3dc9764 2 years ago 231MB [root@lvs ~]# [root@lvs ~]# docker tag ac2cf0f87374 ttq6/ttq6:v0.1 [root@lvs ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ttq6/ttq6 v0.1 ac2cf0f87374 2 minutes ago 745MB httpd latest 7f6a969e81a5 32 hours ago 168MB centos 8 5d0da3dc9764 2 years ago 231MB centos latest 5d0da3dc9764 2 years ago 231MB [root@lvs ~]# [root@lvs ~]# docker login Log in with your Docker ID or email address to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com/ to create one. You can log in with your password or a Personal Access Token (PAT). Using a limited-scope PAT grants better security and is required for organizations using SSO. Learn more at https://docs.docker.com/go/access-tokens/

    Username: 这里输入你容器的账号及密码
    Password:
    WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
    Configure a credential helper to remove this warning. See
    https://docs.docker.com/engine/reference/commandline/login/#credentials-store

    Login Succeeded
    [root@lvs ~]# docker push ttq6/ttq6:v0.1

相关推荐
遇见火星1 天前
Docker Compose 完全入门:一键启动所有容器
运维·docker·容器·docker compose
云原生指北1 天前
Apple Container Machine:把 Linux 搬进 Mac
macos·docker
万岳科技1 天前
教育培训小程序如何构建线上线下一体化教学体系
小程序·apache
隐层漫游者2 天前
2026全网最细Docker容器化实战!从安装配置到Milvus向量数据库部署,一文掌握核心精髓(建议收藏)
docker
加加and减减2 天前
Docker真实安装mysql8教程并优化配置
运维·mysql·docker·容器
半夜燃烧的香烟2 天前
docker 安装minio nginx,配置nginx根据文根路由minio展示图片
java·nginx·docker
qiuziqiqi2 天前
ocker-compose.yml 和Dockerfile 区别
运维·docker·容器
yyuuuzz2 天前
云服务器软件部署的几个常见问题
运维·服务器·开发语言·网络·云计算·php·apache
“码”力全开2 天前
【架构深探】基于Docker与GB28181/RTSP的边缘计算AI视频管理平台:异构算力调度与源码交付实践
人工智能·docker·架构
分布式存储与RustFS2 天前
Apache Iceberg数据湖轻量化搭建:基于Rust开源存储方案
开源·apache·iceberg·rustfs·ai存储·ai memory·s3 table