准备工作
root@localhost ~]# tree /root/apache/
/root/apache/
├── Dockerfile //创建Dockerfile文件
└── files //创建files目录存放源码包和脚本
├── apr-1.7.0.tar.gz
├── apr-util-1.6.1.tar.gz
├── httpd-2.4.53.tar.gz
└── install.sh
编写Dockerfile
[root@localhost apache]# vim Dockerfile
FROM alpine
LABEL MAINTAINER='zjgg 1@2.com'
ENV apr_version=1.7.0 apr_util_version=1.6.1 httpd_version=2.4.53
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_version}.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 apache]# cd files/
[root@localhost files]# vim install.sh
#!/bin/bash
RUN cd /etc/apk &&
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 &&
adduser -SHs /sbin/nologin apache &&
cd /tmp/ &&
tar xf httpd-${httpd_version}.tar.gz &&
cd /tmp/apr-${apr_version} &&
sed -i '/$RM "$cfgfile"/d' configure &&
./configure --prefix=/usr/local/apr && make && make install &&
cd /tmp/apr-util-${apr_util_version} &&
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&
make && make install &&
cd /tmp/httpd-${httpd_version} &&
./configure --prefix=/usr/local/apache
--sysconfdir=/etc/httpd24
--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' /etc/httpd24/httpd.conf &&
rm -rf /tmp/* /var/log/* /var/cache/* &&
apk del gcc g++ make
制作镜像
root@localhost files]# docker build -t httpd:alpine0.1 /root/apache/ [root@localhost files]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE httpd alpine0.1 32b337f815a5 19 minutes ago 266MB
制作容器测试
[root@localhost files]# docker run -d --name qzl -p 80:80 httpd:alpine0.1 7ffd7d3c555ef38e6747d4c30dd523a849cedeb898bb75ad491be47975f29005 [root@localhost files]# curl 172.17.0.3It works!
[root@localhost files]#
上传镜像
[root@localhost apache]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE httpd alpine 32b337f815a5 55 minutes ago 266MB httpd alpine0.1 32b337f815a5 55 minutes ago 266MB 2902314105/httpd lpine 32b337f815a5 55 minutes ago 266MB httpd/alpine0.3 latest 32b337f815a5 55 minutes ago 266MB alpine latest c059bfaa849c 5 months ago 5.59MB [root@localhost apache]# docker tag 32b337f815a5 2902314105/httpd:alpine [root@localhost apache]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 2902314105/httpd alpine 32b337f815a5 56 minutes ago 266MB 2902314105/httpd lpine 32b337f815a5 56 minutes ago 266MB httpd/alpine0.3 latest 32b337f815a5 56 minutes ago 266MB httpd alpine 32b337f815a5 56 minutes ago 266MB httpd alpine0.1 32b337f815a5 56 minutes ago 266MB alpine latest c059bfaa849c 5 months ago 5.59MB [root@localhost apache]# docker push 2902314105/httpd:alpine The push refers to repository [docker.io/2902314105/httpd] 41231878d17b: Pushing 6.52MB/241.3MB 2de084d62e42: Pushed ad2fba5afd5c: Pushing 4.031MB/9.727MB e97333bd8ea1: Pushed 05bad05bc76b: Pushed 8d3ac3489996: Pushing 2.997MB/5.586MB



