一,下载centos的image

1,下载centos最新image

[root@localhost ~]# docker pull centos

2,查看是否成功下载到本地image

[root@localhost ~]# docker images | grep centos
centos latest 470671670cac 7 weeks ago 237MB

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,从docker运行centos8

1,宿主机上创建目录,供docker运行后的容器挂载

[root@localhost liuhongdi]# mkdir /data/nfs
[root@localhost liuhongdi]# mkdir /data/nfs/nfs1

2,运行centos这个image

[root@localhost ~]# docker run --name nfs -v /data/nfs/nfs1:/data/nfs/nfs1 --privileged -d -i -t centos:latest  /usr/sbin/init
2e6fa31c71936674bb048e663d0652e3b227db84df576e1cd1d103608ad2fe56

3,查看此容器是否运行成功

[root@localhost ~]# docker ps -a | grep centos
d0fa7ffc318d centos:latest "/usr/sbin/init" 16 seconds ago Up 15 seconds

4,登录到容器

[root@localhost ~]# docker exec -it nfs /bin/bash
[root@d0fa7ffc318d /]#

三,安装并启动nfs4

1,检查是否有安装nfs

[root@d0fa7ffc318d /]# systemctl status nfs-server
Unit nfs-server.service could not be found.

看来image很简单,自带的软件非常少

从yum安装

[root@d0fa7ffc318d /]# yum install nfs-utils

2,安装成功后,配置nfs

查看nfs的运行状态 :

[root@d0fa7ffc318d /]# systemctl start nfs-server
[root@d0fa7ffc318d /]# systemctl status nfs-server

3,检查nfs是否成功启动:查看端口:

[root@d0fa7ffc318d /]# netstat -anp
20048 mountd
2049 nfs
111 portmap

四,新加nginx账号,用来供nfs的访问使用

1,建立组

[root@d0fa7ffc318d /]# groupadd nginx
[root@d0fa7ffc318d /]# groupmod -g 973 nginx
[root@d0fa7ffc318d /]# grep nginx /etc/group
nginx:x:973:

2,建立用户

[root@d0fa7ffc318d /]# useradd -g nginx -s /sbin/nologin -M nginx
[root@d0fa7ffc318d /]# usermod -u 973 nginx
[root@d0fa7ffc318d /]# grep nginx /etc/passwd
nginx:x:973:973::/home/nginx:/sbin/nologin

五,nfs上配置export一个目录

1,配置export一个目录

[root@2e6fa31c7193 /]# vi /etc/exports

内容:

/data/nfs/nfs1 192.168.1.8(rw,sync,all_squash,anonuid=973,anongid=973)
/data/nfs/nfs1 172.17.0.1(rw,sync,all_squash,anonuid=973,anongid=973)

2,使配置文件的修改生效:

[root@2e6fa31c7193 /]# exportfs -rv
exporting 192.168.1.8:/data/nfs/nfs1
exporting 172.17.0.1:/data/nfs/nfs1

3,在客户端机器上检查nfs服务端输出的文件系统:

[root@localhost ~]# showmount -e 172.17.0.3
Export list for 172.17.0.3:
/data/nfs/nfs1 172.17.0.1,192.168.1.8

4,在客户端上测试挂载

[root@localhost ~]# mount -t nfs 172.17.0.3:/data/nfs/nfs1 /data/mnt/nfs1

5,查看挂载是否成功:列出所有的nfs文件系统

[root@localhost ~]# df -hT | grep nfs
172.17.0.3:/data/nfs/nfs1 nfs 50G 24G 23G 51% /data/mnt/nfs1 

六,安装nginx

1,安装nginx

[root@2e6fa31c7193 /]# yum install nginx

2,配置nginx

1,查看nginx.conf,找到默认的server的配置

[root@2e6fa31c7193 nginx]# more /etc/nginx/nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
}

2,在root         /usr/share/nginx/html;  这个目录下,给nfs建立符号链接

[root@2e6fa31c7193 html]# ln -s /data/nfs/nfs1 ./nfs

3,启动nginx

[root@2e6fa31c7193 html]# systemctl start nginx

4,测试nginx是否生效

从宿主机复制一张图片a1.jpg到/data/nfs/nfs1目录下,

然后访问这个地址进行测试:

http://172.17.0.3/nfs/a1.jpg

说明:172.17.0.3 是nfs服务所在容器的ip

七,commit一个新镜像

[root@localhost ~]# docker commit nfs nfsnginx:0.1
sha256:fa72df9fb74483e90335e99985d8c560d6b6376a66a666e42c3260f79e925691

八,查看新镜像是否生成

[root@localhost ~]# docker images | grep nfsnginx
nfsnginx 0.1 fa72df9fb744 54 seconds ago 328MB

九,测试运行新镜像:

1,启动

[root@localhost ~]# docker run --name nfsnginx -v /data/nfs/nfs1:/data/nfs/nfs1 --privileged -d -i -t nfsnginx:0.1 /usr/sbin/init
ce03496a89b0fcb4011d1c3b945449fabcc27c3438449ce856cbbdf3f2513acb

2,登录,并查看ip:

[root@localhost ~]# docker exec -it nfsnginx /bin/bash
[root@ce03496a89b0 /]# ifconfig | grep inet
inet 172.17.0.4 netmask 255.255.0.0 broadcast 172.17.255.255

3,启动服务:

[root@ce03496a89b0 /]# systemctl start nginx
[root@ce03496a89b0 /]# systemctl start nfs-server

十,查看docker的版本

[root@localhost source]# docker --version
Docker version 19.03.7, build 7141c19

最新文章

  1. 慕课网-Java入门第一季-7-5 Java 中带参无返回值方法的使用
  2. display:inline 和display:inline-block和display:block的区别
  3. Js组件的一些写法【转】
  4. 设计模式:建造者模式(Builder)
  5. javascript 内置对象
  6. python 操作 excel
  7. spring+hibernate
  8. Android 快速选择联系人
  9. PE格式第六讲,导出表
  10. 小强的HTML5移动开发之路(18)——HTML5地理定位
  11. 距离度量以及python实现(一)
  12. 我的第一个Angular2应用
  13. [HEOI2014]逻辑翻译(分治)
  14. (stripTrailingZeros)A == B hdu2054
  15. Page4:线性系统的运动求解以及脉冲响应矩阵与传递函数的关系[Linear System Theory]
  16. xshell提示必须安装最新的更新
  17. 全网最详细的实用的搜索工具【堪称比Everything要好】Listary软件的下载与安装(图文详解)
  18. (转)win7批量创建用户
  19. Kali更新deb源
  20. 4张图看懂delphi 10生成ipa和在iPhone虚拟器上调试(教程)

热门文章

  1. postman -- 环境变量、全局变量使用
  2. Tomcat http转https
  3. Prometheus-Alertmanager告警对接到企业微信
  4. MVC设计模式-笔记1
  5. Oracle学习(二)SQL高级--表数据相关
  6. ASP.NET实现企业微信接入应用实现身份认证
  7. CCNP:重发布及实验
  8. 什么是垃圾搜集(GC)?为什么要有GC呢?
  9. layui动态添加选项卡
  10. 推荐一款轻量小众却高效免费开源windows热键脚本语言Autohotkey