ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

docker 安装nginx以及其对应的文件映射

2021-10-24 12:03:40  阅读:237  来源: 互联网

标签:files Operation 映射 permitted nginx docker proc find


首先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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有