Dockerfile基于centos源码制作httpd镜像
项目目录
[root@podman Dockerfile]# tree
.
├── Dockerfile
├── entrypoint.sh
└── files
├── apr-1.7.0.tar.gz
├── apr-util-1.6.1.tar.gz
└── httpd-2.4.54.tar.gz
编写脚本文件
[root@podman Dockerfile]# vim entrypoint.sh
#!/bin/bash
sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf
exec "$@"
[root@podman Dockerfile]# chmod +x entrypoint.sh
编写Dockerfile文件
[root@podman Dockerfile]# vim Dockerfile
FROM centos
LABEL MAINTAINER='15871816317 15871816317@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 files/httpd-${httpd_version}.tar.gz /usr/src
ADD files/apr-${apr_version}.tar.gz /usr/src
ADD files/apr-util-${apr_util_version}.tar.gz /usr/src
ADD 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"]
创建镜像
[root@podman Dockerfile]# podman build -t httpd:v4 .
[root@podman ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/httpd v4 26cfb05d2b3c 7 minutes ago 417 MB
//测试镜像
[root@podman ~]# podman run -P --name web httpd:v4
[root@podman ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3276f1ed9ce0 localhost/httpd:v4 httpd -D FOREGROU... 35 seconds ago Up 9 seconds ago 0.0.0.0:33377->80/tcp web
[root@podman ~]# podman inspect -l | grep -i 'ipaddr'
"IPAddress": "10.88.0.6",
"IPAddress": "10.88.0.6",
[root@podman ~]#
[root@podman ~]# curl 10.88.0.6
<html><body><h1>It works!</h1></body></html>
上传镜像
[root@podman ~]# podman tag httpd:v4 docker.io/15871816317/httpd:v0.5
[root@podman ~]# podman login docker.io
Username: 15871816317
Password:
Login Succeeded!
[root@podman ~]#
[root@podman ~]# podman push docker.io/2012543034/httpd:v0.5
Getting image source signatures
Copying blob 2653d992f4ef skipped: already exists
Copying blob 62f9dbbce561 skipped: already exists
Copying blob 630ba7777c5c done
Copying blob e29603a74dc4 done
Copying blob 2ac2a2c6d98e done
Copying blob 4fdfd1a17a60 done
Copying config 26cfb05d2b done
Writing manifest to image destination
Storing signatures