- 创建存放apache服务Dockerfile文件的目录
- 上传apr、apr-util、httpd源码包
- 编写Dockerfile文件
- 构建镜像
- 查看镜像
- 基于新镜像创建容器
- 访问网页
[root@localhost ~]# mkdir apache [root@localhost ~]# cd apache/ [root@localhost apache]# mkdir files上传apr、apr-util、httpd源码包
[root@localhost apache]# cd files/ [root@localhost files]# ls apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.48.tar.gz编写Dockerfile文件
[root@localhost apache]# vim Dockerfile # 基础镜像 FROM centos # 作者信息 LABEL WAINTAINER='wjj200112 1234567890@qq.com' # 上传本机上的apache压缩包,传输过程中会自动解压 ADD files/* /usr/local # 切换当前目录 WORKDIR /usr/local/ # 编译安装 RUN yum -y install openssl-devel pcre-devel pcre expat-devel libtool gcc gcc-c++ make which && 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.48 && ./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 # 设置存储卷 VOLUME ["/usr/local/apache/htdocs/"] # 环境变量 ENV PATH /usr/local/apache/bin:$PATH # 启动容器时执行的命令 CMD ["/usr/local/apache/bin/apachectl","-D","FOREGROUND"]构建镜像
[root@localhost ~]# docker build -t wjj200112/httpd:latest apache ........此处省略多行执行过程 Removing intermediate container 45f40500358e ---> bcbbcad642d8 Step 6/9 : EXPOSE 80 ---> Running in 726e648085b3 Removing intermediate container 726e648085b3 ---> c3a106d80d8e Step 7/9 : VOLUME ["/usr/local/apache/htdocs/"] ---> Running in 905edca5b645 Removing intermediate container 905edca5b645 ---> 402d9495825d Step 8/9 : ENV PATH /usr/local/apache/bin:$PATH ---> Running in 677167db82e7 Removing intermediate container 677167db82e7 ---> cc5aab9ffa5f Step 9/9 : CMD ["/usr/local/apache/bin/apachectl","-D","FOREGROUND"] ---> Running in c88a4ee5d4ce Removing intermediate container c88a4ee5d4ce ---> 36472e701b79 Successfully built 36472e701b79 Successfully tagged wjj200112/httpd:latest查看镜像
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE wjj200112/httpd latest 36472e701b79 3 minutes ago 701MB centos latest 5d0da3dc9764 2 months ago 231MB基于新镜像创建容器
[root@localhost ~]# docker run -d -P --name apache wjj200112/httpd:latest fa9e3e4509fed96b79939ec7839ccb484591509de13c25413c87cd7c3025d926 [root@localhost ~]# docker ps ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fa9e3e4509fe wjj200112/httpd:latest "/usr/local/apache/b…" 8 seconds ago Up 7 seconds 0.0.0.0:49153->80/tcp, :::49153->80/tcp apache访问网页
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)