Dockerfile_基于centos源码制作httpd镜像v2
项目目录
[root@web01 httpd]# tree
.
├── Dockerfile
├── packages
│ ├── apr-1.6.5.tar.gz
│ ├── apr-util-1.6.1.tar.gz
│ └── httpd-2.4.54.tar.gz
└── scripts
└── entrypoint.sh
entrypoint.sh脚本文件内容:
[root@web01 httpd]# cat scripts/entrypoint.sh
#!/bin/bash
sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf
exec "$@"
[root@web01 httpd]# chmod +x scripts/entrypoint.sh
基于centos制作httpd镜像的dockerfile
[root@web01 httpd]# vim Dockerfile
FROM centos
LABEL MAINTAINER='yefeng yf021121@163.com'
ENV apr_version=1.6.5 apr_util_version=1.6.1 httpd_version=2.4.54
ENV PATH /usr/local/apache/bin:$PATH
ADD packages/httpd-${httpd_version}.tar.gz /usr/src
ADD packages/apr-${apr_version}.tar.gz /usr/src
ADD packages/apr-util-${apr_util_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 clean all && yum makecache && \
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-gcc+ make && \
rm -rf /tmp/* /usr/src/*
WORKDIR /usr/local/apache
EXPOSE 80
CMD ["httpd","-D","FOREGROUND"]
ENTRYPOINT ["/bin/bash","/entrypoint.sh"]
说明:41行到43行是删除一些不必要的文件以此来减少镜像的大小。
创建镜像
[root@web01 httpd]# podman build -t httpd:v1.2 .
测试镜像:
[root@web01 httpd]# podman run -P --name web httpd:v1.2
[root@web01 httpd]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7d988ce4a400 localhost/httpd:v1.2 httpd -D FOREGROU... 12 seconds ago Up 12 seconds ago 0.0.0.0:44757->80/tcp web
[root@web01 httpd]# podman inspect -l | grep -i 'ipaddr'
"IPAddress": "10.88.0.9",
"IPAddress": "10.88.0.9",
[root@web01 httpd]# curl 10.88.0.9
<html><body><h1>It works!</h1></body></html>
上传至docker hub:
[root@web01 httpd]# podman tag httpd:v1.2 docker.io/guguniao/httpd:v1.2
[root@web01 httpd]# podman login docker.io
Username: guguniao
Password:
Login Succeeded!
[root@web01 httpd]# podman push docker.io/guguniao/httpd:v1.2
[root@web01 httpd]# podman logout
Removed login credentials for docker.io