创建工作目录
[root@docker ~]# mkdir -p /opt/apache/files [root@docker ~]# cd /opt/apache/ [root@docker apache]# touch Dockerfile [root@docker apache]# ls dockerfile files [root@docker apache]# tree . ├── Dockerfile └── files ├── apr-1.7.0.tar.gz ├── apr-util-1.6.1.tar.gz └── httpd-2.4.51.tar.gz
编写dockerfile文件
[root@docker apache]# vim Dockerfile FROM centos //使用centos镜像 LABEL MAINTAINER='sun aabbcc@123.com' ADD files/* /usr/src/ WORKDIR /usr/src/ RUN yum -y install openssl-devel pcre-devel pcre expat-devel libtool gcc gcc-c++ make && cd 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-2.4.51 && ./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 EXPOSE 80 //暴露80端口号 VOLUME ["/usr/local/apache/htdocs/"] //定义宿主机或其他容器的挂载点 CMD ["/usr/local/apache/bin/apachectl","-D","FOREGROUND"] //启动容器时默认启动apache并前台运行
构建镜像
[root@docker apache]# docker build -t 93quan/httpd:v4 . [root@docker apache]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 93quan/httpd v4 2c64fa97abfe 25 seconds ago 703MB
使用新的镜像创建容器
[root@docker apache]# docker run -d -P --name httpd 93quan/httpd:v4 8b639e30e7c2f7876e9a17c80001387035ae444952e60a744f3b98b58e6c4c1b [root@docker apache]# docker port httpd 80/tcp -> 0.0.0.0:49157 80/tcp -> :::49157
浏览器访问测试
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)