程序笔记   发布时间:2022-07-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了2021Docker容器技术全解-nginx和apache共享首页目录实验(8)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

预备3台机器,并且3台机器要全部安装nfs,

首先在m01中创建一个nfs共享目录,然后在另外两台机器中挂载m01的这个共享目录,最后在启动容器时使用-v指定挂载目录到首页

开整:

1在m01中安装nfs并创建共享目录

#安装nfs
[root@m01 ~]# yum -y install nfs-utils rpcbind

#创建共享目录
[root@m01 ~]#mkdir /var/webroot
[root@m01 ~]#chmod 777 /var/webroot

#在配置文件中声明任何主机都可以访问共享目录
[root@m01 ~]#vim /etc/exports
[root@m01 ~]#cat /etc/exports
/var/webroot    *(rw)

#启动nfs服务并关闭防火墙
[root@m01 ~]#systemctl restart nfs-server.service
[root@m01 ~]#systemctl stop firewalld.service

2在web01和web02中挂载nfs共享目录

#查看共享目录
[root@web02 ~]#showmount -e 10.0.0.61
Export list for 10.0.0.61:
/var/webroot *
#在web01中挂载共享目录

#在web02中挂载共享目录
[root@web02 ~]#mount -t nfs -o rw 10.0.0.61:/var/webroot /mnt
[root@web01 ~]#mount -t nfs -o rw 10.0.0.61:/var/webroot /mnt

3在web01中启动nginx容器时将mnt挂载目录指定给容器的默认主页目录

[root@web01 /mnt]#docker run -itd -v /mnt:/usr/local/nginx/html mycentos8:nginx
74cb785019f078466a4182e306c834205842a31733ef9c14f5527de8da04effe
[root@web01 /mnt]#

4在web02中启动httpd容器时将mnt挂载目录指定给容器的默认主页目录

[root@web02 /mnt]#docker run -itd -v /mnt:/var/www/html 10.0.0.61:5000/client-httpd:latest
e39c6a6f37ecbc7e684bb0283a3c61eb047c72d0e4c9dc1166bc9df72f0e8811

5在web01或者web02中任意一台机器中的mnt目录内创建index.html文件并访问测试

[root@web02 /mnt]#vim index.html
[root@web01 /mnt]#docker ps

[root@web01 /mnt]#docker inspect 74cb785019f0
"IPAddress": "172.17.0.2",

#模拟浏览器访问
#web01
[root@web01 /mnt]#curl 172.17.0.2
hello world
#web02
[root@web02 /mnt]#curl 172.17.0.2
hello world

 

大佬总结

以上是大佬教程为你收集整理的2021Docker容器技术全解-nginx和apache共享首页目录实验(8)全部内容,希望文章能够帮你解决2021Docker容器技术全解-nginx和apache共享首页目录实验(8)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: