dockerfile用alpine系统制作apache镜像
dockerfile结构框架
[root@localhost httpd_dockerfile_alpine]# tree
.
├── dockerfile
└── files
├── apr-1.7.0.tar.gz
├── apr-util-1.6.1.tar.gz
├── httpd-2.4.54.tar.gz
└── install.sh
1 directory, 5 files
编写Dockerfile
FROM alpine
LABEL MAINIAINER='qzl 1@2.com'
ENV httpd_edition 2.4.54
ENV PATH /usr/local/apache/bin:$PATH
EXPOSE 80
ADD files/apr-1.7.0.tar.gz /tmp/
ADD files/apr-util-1.6.1.tar.gz /tmp/
ADD https://downloads.apache.org/httpd/httpd-${httpd_edition}.tar.gz /tmp/
ADD files/install.sh /tmp/
RUN /bin/sh /tmp/install.sh
WORKDIR /usr/local/apache
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
编写脚本
[root@localhost httpd_dockerfile_alpine]# vim files/install.sh
#!/bin/bash
adduser -SHs /sbin/nologin apache && \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories &&\
apk add --no-cache -U gcc g++ make openssl-dev pcre-dev expat-dev libtool libc-dev libcurl && \
cd /tmp/ && \
tar xf httpd-${httpd_edition}.tar.gz && \
cd /tmp/apr-1.7.0 && \
sed -i '/$RM "$cfgfile"/d' configure && \
./configure --prefix=/usr/local/apr && \
make && make install && \
cd ../apr-util-1.6.1/ && \
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && \
make && make install && \
cd ../httpd-${httpd_edition}/ && \
./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 && \
sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf && \
rm -rf /tmp/* /var/log/* /var/cache/* &&\
apk del gcc g++ make //删除
制作镜像
[root@localhost httpd_dockerfile_alpine]# docker build -t httpdtest:v1 .
//注意显示的大小,有可能会因为缓存不变,就创建容器进去查看大小
[root@localhost httpd_dockerfile_alpine]# docker images
httpdtest v1 a8474d831b2f 31 minutes ago 92.2MB
制作容器测试
[root@localhost httpd_dockerfile_alpine]# docker run -d --name web --restart always -p 81:80 2902314105/httpd_alpine:v0.1
82deb1597ab70347b44f7a2a6cf3b0441c6543386108cbe70d7d4c4ca41deaab
[root@localhost httpd_dockerfile_alpine]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82deb1597ab7 2902314105/httpd_alpine:v0.1 "/usr/local/apache/b…" 12 seconds ago Up 11 seconds 0.0.0.0:81->80/tcp, :::81->80/tcp web
//在已创建的容器添加参数,--restart=always 容器随docker重启一起重启
[root@localhost httpd_dockerfile_alpine]# docker container update --restart=always web
web
//访问容器IP
[root@localhost httpd_dockerfile_alpine]# curl 172.17.0.4
<html><body><h1>It works!</h1></body></html>
访问测试