Dockerfile基于centos源码制作httpd镜像
项目目录
[root@loaclhost ~]# ls
anaconda-ks.cfg dockerfile_httpd
[root@loaclhost ~]# cd dockerfile_httpd/
[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
编辑entrypoint.sh脚本文件内容
[root@loaclhost dockerfile_httpd]# mkdir scripts
[root@loaclhost dockerfile_httpd]# cd scripts/
[root@loaclhost scripts]# touch entrypoint.sh
[root@loaclhost scripts]# cat entrypoint.sh
#!/bin/bash
sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf
exec "$@"
[root@loaclhost scripts]# chmod +x entrypoint.sh
基于centos制作httpd镜像的dockerfile
[root@loaclhost dockerfile_httpd]# vim Dockerfile
# This dockerfile uses the centos image
# Httpd Version 2.4 - edtion 54
# Author: zhangjunqiang
FROM centos
LABEL MAINTAINER='zhangjunqiang 3318861575@qq.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 httpd/httpd-${httpd_version}.tar.gz /usr/src
ADD httpd/apr-${apr_version}.tar.gz /usr/src
ADD httpd/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 -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@loaclhost dockerfile_httpd]# podman build -t httpd:v0.3 .
测试镜像
[root@loaclhost dockerfile_httpd]# podman run -P --name web1 httpd:v0.3
[root@loaclhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b4eb49855a41 localhost/httpd:v0.3 httpd -D FOREGROU... 3 minutes ago Up 3 minutes ago 0.0.0.0:35565->80/tcp web1
[root@loaclhost ~]# podman inspect -l |grep -i ipadd
"IPAddress": "10.88.0.2",
"IPAddress": "10.88.0.2",
[root@loaclhost ~]# curl 10.88.0.2
<html><body><h1>It works!</h1></body></html>
上传至docker hub
[root@loaclhost dockerfile_httpd]# podman tag localhost/httpd:v0.3 docker.io/zjunwhite/httpd:v0.3
[root@loaclhost dockerfile_httpd]# podman login docker.io
Username: zjunwhite
Password:
Login Succeeded!
[root@loaclhost dockerfile_httpd]# podman push docker.io/zjunwhite/httpd:v0.3
[root@loaclhost dockerfile_httpd]# podman logout
Removed login credentials for docker.io
ocker.io/zjunwhite/httpd:v0.3
[root@loaclhost dockerfile_httpd]# podman logout
Removed login credentials for docker.io