文章来源:
1.添加镜像
# docker pull httpd2.4
2.创建httpd文件
# mkdir /data/httpd2.4
3.启动apache
# docker run -it -p 82:80 -d httpd
4.复制配置文件
#### 复制根目录 # docker cp httpd:/usr/local/apache2/htdocs /data/httpd2.4/www #### 复制配置文件 # mkdir /data/httpd2.4/conf # docker cp httpd:/usr/local/apache2/conf/httpd.conf /data/httpd2.4/conf/httpd.conf #### 复制日志文件 # docker cp httpd:/usr/local/apache2/logs /data/httpd2.4/logs
5.删除httpd容器
# docker rm -f httpd
6.配置httpd2.4并且启动
# docker run -it -p 82:80 --name httpd2.4 --restart always -v /data/httpd2.4/www/:/usr/local/apache2/htdocs/ -v /data/httpd2.4/conf/httpd.conf:/usr/local/apache2/conf/httpd.conf -v /data/httpd2.4/logs/:/usr/local/apache2/logs/ -d httpd
7.配置说明
-p 80:80 :将容器的80端口映射到主机的80端口
-v /data/httpd2.4/www/:/usr/local/apache2/htdocs/ :将主机中当前目录下的www目录挂载到容器的/usr/local/apache2/htdocs/
-v /data/httpd2.4/conf/httpd.conf:/usr/local/apache2/conf/httpd.conf :将主机中当前目录下的conf/httpd.conf文件挂载到容器的/usr/local/apache2/conf/httpd.conf
-v /data/httpd2.4/logs/:/usr/local/apache2/logs/ :将主机中当前目录下的logs目录挂载到容器的/usr/local/apache2/logs/
文章来源: