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

    <html><body>

    It works!

    </body></html> [root@lvs ~]# [root@lvs ~]# docker commit -p ttq6 //创建 sha256:ac2cf0f87374d4726a2e7b3631fbe0af711c965fcdeb3e2ec4c52cbd90d25fdd [root@lvs ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 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

相关推荐
muyun28003 天前
Docker 下部署 Elasticsearch 8 并集成 Kibana 和 IK 分词器
elasticsearch·docker·容器
是Dream呀3 天前
时序数据库选型指南:Apache IoTDB企业级解决方案深度解析
apache·时序数据库·iotdb
一个天蝎座 白勺 程序猿3 天前
Apache IoTDB(5):深度解析时序数据库 IoTDB 在 AINode 模式单机和集群的部署与实践
数据库·apache·时序数据库·iotdb·ainode
hashiqimiya3 天前
centos配置环境变量jdk
linux·运维·centos
百锦再3 天前
[特殊字符] Python在CentOS系统执行深度指南
开发语言·python·plotly·django·centos·virtualenv·pygame
傻傻虎虎3 天前
【Docker】常用帮忙、镜像、容器、其他命令合集(2)
运维·docker·容器
2401_897930063 天前
使用Docker轻松部署Neo4j图数据库
数据库·docker·neo4j
LeeZhao@3 天前
【AI推理部署】Docker篇04—Docker自动构建镜像
人工智能·docker·容器
程思扬3 天前
利用JSONCrack与cpolar提升数据可视化及跨团队协作效率
网络·人工智能·经验分享·docker·信息可视化·容器·架构
落日漫游3 天前
dockercompose和k8s区别
docker·kubernetes