首先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
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
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
放置文件 测试起来:
大功告成