docker 安装nginx以及其对应的文件映射
作者:互联网
首先https://hub.docker.com/search?q=nginx&type=image docker镜像官网查阅相关资料
获取镜像文件:
docker pull nginx
诉求:不但要 有一个容器,还要映射发布目录到主机,映射配置到主机 用宿主机的8001端口对应容器的80
由于不清楚生成的容器中这些目录,我们先跑起来一个容器,进去看一看就知道了。
测试 跑一个容器:
docker run -d --name nginx01 -p 80:80 nginx
进入容器:
docker exec -it nginx01 bash
搜索nginx相关:
find / -name nginx
root@d95b2788b9cc:/# find / -name nginx
/etc/default/nginx
/etc/init.d/nginx
/etc/logrotate.d/nginx
/etc/nginx
find: '/proc/1/map_files': Operation not permitted
find: '/proc/24/map_files': Operation not permitted
find: '/proc/25/map_files': Operation not permitted
find: '/proc/26/map_files': Operation not permitted
find: '/proc/27/map_files': Operation not permitted
find: '/proc/28/map_files': Operation not permitted
find: '/proc/36/map_files': Operation not permitted
/usr/lib/nginx
/usr/sbin/nginx
/usr/share/doc/nginx
/usr/share/nginx
/var/cache/nginx
/var/log/nginx
进入这几个目录发现:
/usr/share/nginx目录下的html为映射文件目录
这几个目录中没有发现配置文件的踪影…
再次精准检索:
find / -name nginx.conf
root@d95b2788b9cc:/var/cache/nginx# find / -name nginx.conf
/etc/nginx/nginx.conf
find: '/proc/1/map_files': Operation not permitted
find: '/proc/24/map_files': Operation not permitted
find: '/proc/25/map_files': Operation not permitted
find: '/proc/26/map_files': Operation not permitted
find: '/proc/27/map_files': Operation not permitted
find: '/proc/28/map_files': Operation not permitted
find: '/proc/52/map_files': Operation not permitted
于是找到路配置文件目录。
我们宿主机建立映射文件 体检建立好目录(否则run的时候你想要的文件夹会意外的变成了文件)
/mydata/nginx/html/ 映射文件
对应容器文件夹 /usr/share/nginx/html/
把配置文件拿过来:
docker cp nginx01:/etc/nginx/nginx.conf /mydata/nginx/conf
/mydata/nginx/conf/ nginx.conf配置文件夹
对应容器文件夹/etc/nginx/nginx.conf
删除测试容器:
docker rm nginx01
基于我们收集的信息,run我们的目标容器
docker run
--name nginx
-p 8001:80
-v /mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
-v /mydata/nginx/html:/usr/share/nginx/html
-d nginx
放置文件 测试起来:
大功告成
标签:files,Operation,映射,permitted,nginx,docker,proc,find 来源: https://blog.csdn.net/qq_17040587/article/details/120861252