先看一下大致的目录结构,一会这些文件都会用到
看一下Dockerfile
FROM centos:7 WORKDIR /usr/local/src #指定本地tar包和目标容器地址 ADD httpd-2.4.41.tar.gz /usr/local/src WORKDIR httpd-2.4.41 #编译安装apache RUN yum -y install epel-release.noarch && yum makecache fast RUN yum install -y gcc make apr-devel apr apr-util apr-util-devel pcre-devel RUN ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so RUN make RUN make install RUN rm -rf /usr/local/src/* #修改apache配置文件 RUN sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g' /usr/local/apache2/conf/httpd.conf #启动apache服务 RUN /usr/local/apache2/bin/httpd #复制服务启动脚本并设置权限 ADD run.sh /usr/local/sbin/run.sh RUN chmod 755 /usr/local/sbin/run.sh #开放80端口 EXPOSE 80 CMD ["/usr/local/sbin/run.sh"]
在当前目录构建镜像
docker build -t my-httpd:v1 .
启动一个容器设置挂载
docker run -itd --name http01 -p 80:80 -v /dockfile/httpd/htdocs:/usr/local/apache2/htdocs httpd:v1
查看是否成功
测试文件映射
[root@localhost htdocs]# echo " ni hao 01! " > index.html
测试