Docker基于centos镜像编译安装httpd

Docker基于centos镜像编译安装httpd

项目目录:

[root@localhost ~]# tree
.
├── anaconda-ks.cfg
└── apache
    ├── Dockerfile
    └── packages
        ├── apr-1.7.0.tar.gz
        ├── apr-util-1.6.1.tar.gz
        └── httpd-2.4.46.tar.bz2

制作httpd镜像的Dockerfile

[root@localhost ~]# vim apache/Dockerfile 

FROM centos

LABEL MAINTAINER='leidazhuang 123@qq.com'

ENV apr_version=1.7.0 apr_util_version=1.6.1 httpd_version=2.4.46

ADD packages/apr-${apr_version}.tar.gz /usr/src
ADD packages/apr-util-${apr_util_version}.tar.gz /usr/src
ADD packages/httpd-${httpd_version}.tar.bz2 /usr/src

RUN yum -y install make gcc gcc-c++ openssl-devel pcre-devel expat-devel libtool libxml2-devel &&\
    useradd -r -M -s /sbin/nologin apache &&\
    cd /usr/src/apr-${apr_version} &&\
    sed -i '/$RM "$cfgfile"/d' configure &&\
    ./configure --prefix=/usr/local/apr && make && make install &&\
    cd /usr/src/apr-util-${apr_util_version} &&\
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&\
    make && make install &&\
    cd /usr/src/httpd-${httpd_version} &&\
    ./configure --prefix=/usr/local/apache \
    --sysconfdir=/etc/httpd24 \
    --enable-so \
    --enable-ssl \
    --enable-cgi \
    --enable-rewrite \
    --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 && make && make install &&\
    sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf

WORKDIR /usr/local/apache

EXPOSE 80 443

ENTRYPOINT /usr/local/apache/bin/apachectl  -DFOREGROUND

创建镜像

[root@localhost apache]docker build -t httpd:v0.1 /root/apache/

Step 10/10 : ENTRYPOINT /usr/local/apache/bin/apachectl  -DFOREGROUND
 ---> Running in 066680bb2291
Removing intermediate container 066680bb2291
 ---> 2acab10c568a
Successfully built 2acab10c568a
Successfully tagged httpd:v0.1

启动容器,开放端口

[root@localhost apache]# docker run -it --rm --name ldz -p 80:80 httpd:v0.1
# 正常运行

查看端口信息

[root@localhost ~]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port      
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*         
LISTEN      0           128                    0.0.0.0:80                  0.0.0.0:*         
LISTEN      0           128                       [::]:22                     [::]:* 

访问测试

[root@localhost ~]# curl 192.168.110.20
<html><body><h1>It works!</h1></body></html>

通过网页访问

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
1. 安装DockerCentOS安装Docker,可以使用官方的安装脚本。打开终端并运行以下命令: ``` $ curl -fsSL https://get.docker.com/ | sh ``` 如果您的系统上没有curl,请先安装它: ``` $ yum install curl ``` 2. 下载PostgreSQL的Dockerfile 我们可以从官方的Docker Hub上下载PostgreSQL的Dockerfile。使用以下命令: ``` $ curl -O https://raw.githubusercontent.com/docker-library/postgres/master/13/alpine/Dockerfile ``` 3. 编辑Dockerfile 使用vim或nano等编辑器打开下载下来的Dockerfile文件,进行以下配置: ``` FROM centos:latest ENV POSTGRES_USER postgres ENV POSTGRES_PASSWORD postgres ENV POSTGRES_DB postgres RUN yum update -y && \ yum install -y postgresql-server postgresql-contrib && \ yum clean all USER postgres RUN initdb --encoding=UTF8 --locale=C -D /var/lib/pgsql/data && \ pg_ctl -D /var/lib/pgsql/data -l logfile start && \ psql --command "CREATE USER postgres WITH SUPERUSER PASSWORD 'postgres';" && \ createdb -O postgres postgres VOLUME ["/var/lib/pgsql/data"] EXPOSE 5432 CMD ["postgres", "-D", "/var/lib/pgsql/data", "-c", "config_file=/var/lib/pgsql/data/postgresql.conf"] ``` 4. 构建Docker镜像 使用以下命令构建Docker镜像: ``` $ docker build -t my_postgresql . ``` 这将构建一个名为“my_postgresql”的新Docker镜像。 5. 运行PostgreSQL容器 使用以下命令运行PostgreSQL容器: ``` $ docker run -d -p 5432:5432 --name my_postgresql_container my_postgresql ``` 这将创建一个名为“my_postgresql_container”的新容器,并将容器的端口5432映射到主机的端口5432。 6. 测试PostgreSQL容器 为了测试新的PostgreSQL容器,请使用以下命令: ``` $ psql -h localhost -U postgres -d postgres ``` 您应该现在可以通过psql连接到PostgreSQL容器。 现在您已经成功地使用Docker创建了一个基于CentOS的PostgreSQL镜像,并运行了一个新的PostgreSQL容器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值