Dockerfile制作httpd镜像
1.基本操作
//创建存放Dockerfie的目录和创建Dockerfile和存放httpd和apr,apr-util的目录
[root@loaclhost dockerfile_httpd]# tree
.
├── Dockerfile
├── httpd
│ ├── apr-1.6.5.tar.gz
│ ├── apr-util-1.6.1.tar.gz
│ └── httpd-2.4.54.tar.gz
└── scripts
└── entrypoint.sh
//查看脚本的内容
[root@loaclhost dockerfile_httpd]# cat scripts/entrypoint.sh
#!/bin/bash
sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf
exec "$@"
//给脚本添加执行权限
[root@loaclhost dockerfile_httpd]# chmod +x scripts/entrypoint.sh
2.用centos制作httpd镜像的dockerfile
FROM centos
LABEL MAINTAINER='huangweifeng 431143766@qq.com'
ENV apr_version=1.6.5 apr_util_version=1.6.1 httpd_version=2.4.54
ENV PATH /usr/local/apachectl/bin:$PATH
ADD httpd/apr-${apr_version}.tar.gz /usr/src
ADD httpd/apr-util-${apr-util_version}.tar.gz /usr/src
ADD httpd/httpd-${httpd_version}.tar.gz /usr/src
ADD scripts/entrypoint.sh /
RUN rm -f /etc/yum.repos.d/* && \
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo && \
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo && \
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 \
--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 &&\
//下面两行是用来删除一些没用的文件
yum clean all && yum -y remove gcc gcc-c++ make && \
rm -rf /tmp/* /usr/src/*
WORKDIR /usr/local/apache
EXPOSE 80
CMD ["httpd","-D","FOREGROUND"]
ENTRYPOINT ["/bin/bash","/entrypoint.sh"]
3.创建镜像
[root@loaclhost dockerfile_httpd]# podman build -t httpd:v0.2 .
4.测试刚刚创建的镜像
[root@loaclhost dockerfile_httpd]# podman run -P --name wjh httpd:v3
[root@loaclhost dockerfile_httpd]# podman inspect -l|grep -i ipadd
"IPAddress": "10.88.0.14",
"IPAddress": "10.88.0.14",
[root@loaclhost dockerfile_httpd]# curl 10.88.0.14
<html><body><h1>It works!</h1></body></html>
5.上传镜像
[root@loaclhost dockerfile_httpd]# podman tag localhost/httpd:v3 docker.io/15072814090/httpt:v3
[root@loaclhost dockerfile_httpd]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/httpd v3 a9d6150e39ba 5 minutes ago 417 MB
docker.io/15072814090/httpt v3 a9d6150e39ba 5 minutes ago 417 MB
[root@loaclhost dockerfile_httpd]# podman push docker.io/15072814090/httpd:v3
50e39ba 5 minutes ago 417 MB
[root@loaclhost dockerfile_httpd]# podman push docker.io/15072814090/httpd:v3
本文含有隐藏内容,请 开通VIP 后查看