准备项目目录
[root@localhost ~]# tree
.
├── anaconda-ks.cfg
├── apache
├── Dockerfile
└── 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]# pwd
/root/apache
[root@localhost apache]# cat Dockerfile
FROM alpine
LABEL MANTAINER "asd 1@2.com"
ENV VERSION 2.4.53
ENV PATH /usr/local/apache/bin:$PATH
EXPOSE 80 443
ADD files/apr-1.7.0.tar.gz /tmp/
ADD files/apr-util-1.6.1.tar.gz /tmp/
ADD files/httpd-${VERSION}.tar.gz /tmp/
RUN adduser -SHs /sbin/nologin apache && \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk add --no-cache -U openssl-dev pcre-dev expat-dev libtool gcc libc-dev make && \
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-${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
WORKDIR /usr/local/apache
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
如果想缩小镜像的话就执行一下操作
//install.sh
[root@localhost apache]# pwd
/root/apache
[root@localhost apache]# \cp Dockerfile files/install.sh
[root@localhost files]# cat install.sh
#!/bin/sh
adduser -SHs /sbin/nologin apache && \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk add --no-cache -U openssl-dev pcre-dev expat-dev libtool gcc libc-dev make && \
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-${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 && \
apk del --no-cache -U gcc libc-dev make && \
rm -rf /tmp/*
//Dockerfile
[root@localhost apache]# cat Dockerfile
FROM alpine
LABEL MANTAINER "asd 1@2.com"
ENV VERSION 2.4.53
ENV PATH /usr/local/apache/bin:$PATH
EXPOSE 80 443
ADD files/apr-1.7.0.tar.gz /tmp/
ADD files/apr-util-1.6.1.tar.gz /tmp/
ADD files/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]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: lzx17683765691
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@localhost apache]# docker push lzx17683765691/httpd-alpine
Using default tag: latest
The push refers to repository [docker.io/lzx17683765691/httpd-alpine]
fa9687ec10c4: Pushed
4d06bdd19785: Pushed
f11225bdc9b1: Pushed
4e3c5c3c85b2: Pushed
566c27ffa302: Pushed
4fc242d58285: Mounted from library/alpine
latest: digest: sha256:b1c005cc32cdde2a78dabde30ea7e6fc3497ff026480f556956e3f0b54be13c1 size: 1579
