[root@localhost ~]# tree
.
├── anaconda-ks.cfg
└── apache
├── Dockerfile
└── packages
├── apr-1.7.0.tar.bz2
├── apr-util-1.6.1.tar.bz2
└── httpd-2.4.43.tar.bz2
[root@localhost ~]# vim apache/Dockerfile
FROM centos
LABEL MAINTAINER='zdjyh071216@126.com'
ENV apr_version 1.7.0
ENV apr_util_version 1.6.1
ENV httpd_version 2.4.43
ADD packages/apr-${apr_version}.tar.bz2 /usr/src
ADD packages/apr-util-${apr_util_version}.tar.bz2 /usr/src
ADD packages/httpd-${httpd_version}.tar.bz2 /usr/src
RUN 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 \
--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
WORKDIR /usr/local/apache
EXPOSE 80 443
ENTRYPOINT /usr/local/apache/bin/apachectl -DFOREGROUND
//创建镜像
[root@localhost]# docker build -t httpd:v0.1 /root/apache/
//启动容器,开放端口
[root@localhost]# docker run -it --rm --name yh -p 80:80 httpd:v0.1
//查看端口
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
//访问测试
[root@localhost ~]# curl 192.168.35.137
<html><body><h1>It works!</h1></body></html>
//查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yh/httpd v0.1 40087ea739c8 10 minutes ago 688MB
centos latest 300e315adb2f 7 months ago 209MB
//打标签
[root@localhost ~]# docker tag 40087ea739c8 itmiao16/httpd:v0.1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
itmiao16/httpd v0.1 40087ea739c8 31 minutes ago 688MB
wssswsss/apache:v1.0 v0.1 40087ea739c8 31 minutes ago 688MB
centos latest 300e315adb2f 7 months ago 209MB
[root@localhost ~]# docker login
Authenticating with existing credentials...
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 ~]# docker push wssswsss/apache:v1.0