开源程序做网站任务,手机百度网页版登录入口,微信开店小程序怎么做,wordpress直播主题目录 传送门 
从安装redis说起 
什么是容器卷挂载 
操作系统的挂载 
日志文件一般是首恶元凶 
挂载命令 
容器卷挂载  
卷挂载命令 
启动时挂载 
查看挂载卷信息 
容器卷管理 
查看卷列表 
创建容器卷 
具名挂载与匿名挂载 
具名挂载 传送门 
docker系列1#xff…目录 传送门 
从安装redis说起 
什么是容器卷挂载 
操作系统的挂载 
日志文件一般是首恶元凶 
挂载命令 
容器卷挂载  
卷挂载命令 
启动时挂载 
查看挂载卷信息 
容器卷管理 
查看卷列表 
创建容器卷 
具名挂载与匿名挂载 
具名挂载 传送门 
docker系列1docker安装 
docker系列2阿里云镜像加速器 docker系列3docker镜像基本命令 
docker系列4docker容器基本命令 
docker系列5docker安装nginx 
docker系列6docker安装redis 
docker系列7docker安装ES 
从安装redis说起 
在前面几节通过docker安装过了nginx、redis和ES会发现通过docker安装运行软件的过程都差不多。但是在redis章节时有一点区别在使用Docker容器管理时有时候需要对Redis进行配置但是Docker镜像中并没有默认的redis.conf需要手动设置redis.conf文件。 
当时的解决方案是在启动命令中加入了一个配置 docker run --name test_redis -p 6379:6379 -v /root/redis/redis.conf:/usr/local/etc/redis/redis.conf -d redis其中的-v /root/redis/redis.conf:/usr/local/etc/redis/redis.conf就是容器卷挂载 
什么是容器卷挂载 
在具体解释上面这条命令参数之前先使用docker run --help看下官方的解释 
-v, --volume list                    Bind mount a volume  绑定挂载一个卷可以指定多个为一个列表--volume-driver string           Optional volume driver for the container  指定容器卷驱动--volumes-from list              Mount volumes from the specified container(s)光看上面这个解释第一次接触的可能还是比较模糊要说清楚这个问题可以先从传统操作操作系统的的挂载讲起 
操作系统的挂载 
日志文件一般是首恶元凶 
不知道你有没有过这种经历在linux上面搭建的应用系统服务跑了一段时间之后会发生磁盘被占满了甚至连登录服务器都登录不上而且一般是客户上报的错误开发很慌啊~~。 图片来自网络  最后各种排查发现在是日志过大比如nacos默认的系统日志XXL-job的触发日志导致磁盘容量不够这时可能就会让运维背锅 
每隔一段时间手动去服务器删除日志文件相关文件或者写个cron任务自动删除日志文件 
这种比较暴力的处理方式在不那么草台班子的公司可能不会出现这时运维能力强的公司一般会要求日志必须保留多久或者做备份 
对服务器各项指标做监控并配置对应的自动化运维手段对日志备份提前对日志容量做评估配置对应的磁盘容量水位做预留要求开发将日志输出到指定挂载盘上空间足够大 
对于传统自建的服务器可以在购买物理机的时候选用磁盘容量比较大的机器这个时候如果硬盘不量不够可以挂载单独的外设硬盘。随着云计算的发展很多公司上云之后都会购买云主机虚拟机来搭建应用服务这样扩容很方便且在一定规模下降低成本这个命题最近非常火此处不过多讨论持保留很意见这样就出现了NFS还有OSS等网络存储设备。不管是物理机还是虚拟机的挂载都可以统一称为磁盘挂载用来区分前面提到的docker容器卷挂载。下图是实际项目使用的一种解决方案 挂载命令 
对于挂载命令不是这里的重点可以自行搜索或者查看 
容器卷挂载  
而容器的卷挂载跟磁盘挂载其实原理相似不过容器卷挂载的初衷更多的是由于容器内的存储是易失的不能持久化虽然容器容量也是其中很重要的一个原因。对此看下官方的解释 By default all files created inside a container are stored on a writable container layer. This means that: The data doesnt persist when that container no longer exists, and it can be difficult to get the data out of the container if another process needs it. A containers writable layer is tightly coupled to the host machine where the container is running. You cant easily move the data somewhere else. Writing into a containers writable layer requires a storage driver to manage the filesystem. The storage driver provides a union filesystem, using the Linux kernel. This extra abstraction reduces performance as compared to using data volumes, which write directly to the host filesystem. Docker has two options for containers to store files on the host machine, so that the files are persisted even after the container stops: volumes, and bind mounts. ---------------------------------------------- 以下为机译 ----------------------------------------------------- 默认情况下在容器内创建的所有文件都存储在可写容器层上。这意味着 当容器不存在时数据不会持久存在如果另一个进程需要则很难将数据从容器中取出。 容器的可写层与运行容器的主机紧密耦合。你不能轻易地将数据移动到其他地方。 写入容器的可写层需要一个存储驱动程序来管理文件系统。存储驱动程序使用Linux内核提供了一个联合文件系统。与使用直接写入主机文件系统的数据卷相比这种额外的抽象降低了性能。 Docker为容器在主机上存储文件提供了两个选项这样即使在容器停止后文件也会被持久化卷和绑定装载。 以上面的redis为例docker运行redis镜像时不一定要强行增加-v才行 
在宿主机放置一分redis.conf文件将上面的redis.conf文件拷贝到容器中修改容器中的redis.conf文件达到修改redis配置的目的 
现在来启动一个redis容器docker run -it -d --name myredis redis 将宿主机的redis.conf文件拷贝到容器中docker cp /root/redis/redis.conf myredis:/usr/local/etc/redis-conf/redis.conf 进入容器查看redis.conf文件 docker exec -it myredis /bin/bash 后面就可以指定redis.conf文件启动服务了注意这里的redis.conf文件需要跟redis的版本一致不然可能会启动失败 
卷挂载命令 
虽然上述方式可以达到跟卷挂载一样的效果但是还是不如挂载来的方便先看一下挂载命令 
启动时挂载 
前面的redis运行时通过-v命令称作启动时自动挂载 
docker run --name test_redis -p 6379:6379 -v /root/redis/redis.conf:/usr/local/etc/redis/redis.conf -d redis 
-v表明进行卷挂载后面接着路径宿主机路径:容器内路径比如/root/redis/redis.conf表示宿主机上面的redis.conf路径/usr/local/etc/redis/redis.conf表示容器内的路径 
既然是路径除了上面挂载文件之外肯定也可以挂载目录的。比如在刚才的命令中增加一个数据目录-v /root/redis/data:/usr/local/etc/redis/data 然后分别查看宿主机与容器内的目录 对于这一点官网的解释 If you start a container with a volume that doesnt yet exist, Docker creates the volume for you 从上面磁盘挂载特性在容器内操作文件就跟操作本地一样。比如在容器内创建一个测试文件test.txt然后在宿主机观察一下 从这说明容器的挂载成功了  
查看挂载卷信息 
如果要查看刚才redis挂载的卷信息可以通过如下docker命令docker inspect 容器名 在显示的容器里面查找到挂载卷信息 容器卷管理 
查看卷列表 
如果要查看刚才redis挂载的卷信息除了可以通过如下docker命令docker inspect 容器名之外还有专门的卷查看命令docker volume ls 但是这个卷名字VOLUME NAME怎么这么奇怪 因为这个是卷挂载自动生成的挂载卷名称也称为匿名挂载。仔细看的话前面的inspect里面有一项里面的Name也是类似9287eb2555a9b48bb1f91c69489dd806e777aca0b22448d0d718e0c1c4bb7640 
{Type: volume,Name: 9287eb2555a9b48bb1f91c69489dd806e777aca0b22448d0d718e0c1c4bb7640,Source: /var/lib/docker/volumes/9287eb2555a9b48bb1f91c69489dd806e777aca0b22448d0d718e0c1c4bb7640/_data,Destination: /data,Driver: local,Mode: ,RW: true,Propagation: }而这一项就对应docker volume ls里面的一个卷 如果查看此挂载卷信息 会发现的确是刚才创建的而匿名卷会默认跟宿主机的/var/lib/docker/volumes/VOLUME NAME/_data关联起来 
现在再测试一下启动一个新的容器 
docker run --name test_redis3 -p 6379:6379 -v -v /root/redis/data2:/usr/local/etc/redis/data2 -d redis 
运行之后查看容器卷信息 
Mounts: [{Type: bind,Source: /root/redis/data2,Destination: /usr/local/etc/redis/data2,Mode: ,RW: true,Propagation: rprivate},{Type: volume,Name: 109806e8fe95be922b8cb8b6a54bcc7bc664edaaca0cc2803dbb9c41bfce206c,Source: /var/lib/docker/volumes/109806e8fe95be922b8cb8b6a54bcc7bc664edaaca0cc2803dbb9c41bfce206c/_data,Destination: /data,Driver: local,Mode: ,RW: true,Propagation: }] 
创建容器卷 
除了前面介绍的启动时自动挂载还可以手动创建容器卷 
# my-vol为卷名称
docker volume create my-vol 执行一下上面的命令并查看对应的卷列表 具名挂载与匿名挂载 
但是你会发现这种指定卷名称的创建方式卷的名称不再是一种看不懂的字符串了。这种方式也叫作具名挂载 不过此时需要挂载的卷的宿主机路径都默认放到docker指定的目录下面了。而匿名挂载可以动态指定宿主机路径挂载的目录 
具名挂载 
有了手动创建的卷那现在也可以通过启动时挂载具体的卷 
docker run --name test_redis -p 6379:6379 -v my-vol:/usr/local/etc/redis/data -d redis 文章转载自: http://www.morning.zzgkk.cn.gov.cn.zzgkk.cn http://www.morning.pfnrj.cn.gov.cn.pfnrj.cn http://www.morning.qgjgsds.com.cn.gov.cn.qgjgsds.com.cn http://www.morning.kdxzy.cn.gov.cn.kdxzy.cn http://www.morning.wwkft.cn.gov.cn.wwkft.cn http://www.morning.mbbgk.com.gov.cn.mbbgk.com http://www.morning.lhjmq.cn.gov.cn.lhjmq.cn http://www.morning.kndyz.cn.gov.cn.kndyz.cn http://www.morning.cjqcx.cn.gov.cn.cjqcx.cn http://www.morning.bqdpy.cn.gov.cn.bqdpy.cn http://www.morning.fdsbs.cn.gov.cn.fdsbs.cn http://www.morning.jqwpw.cn.gov.cn.jqwpw.cn http://www.morning.jljwk.cn.gov.cn.jljwk.cn http://www.morning.xkzr.cn.gov.cn.xkzr.cn http://www.morning.fnbtn.cn.gov.cn.fnbtn.cn http://www.morning.mtzyr.cn.gov.cn.mtzyr.cn http://www.morning.hgtr.cn.gov.cn.hgtr.cn http://www.morning.tgqzp.cn.gov.cn.tgqzp.cn http://www.morning.qfrsm.cn.gov.cn.qfrsm.cn http://www.morning.rmlz.cn.gov.cn.rmlz.cn http://www.morning.mjbnp.cn.gov.cn.mjbnp.cn http://www.morning.kyfrl.cn.gov.cn.kyfrl.cn http://www.morning.jgmlb.cn.gov.cn.jgmlb.cn http://www.morning.ktfbl.cn.gov.cn.ktfbl.cn http://www.morning.dbjyb.cn.gov.cn.dbjyb.cn http://www.morning.sqmlw.cn.gov.cn.sqmlw.cn http://www.morning.fkmyq.cn.gov.cn.fkmyq.cn http://www.morning.c7627.cn.gov.cn.c7627.cn http://www.morning.jpbpc.cn.gov.cn.jpbpc.cn http://www.morning.lpqgq.cn.gov.cn.lpqgq.cn http://www.morning.c7625.cn.gov.cn.c7625.cn http://www.morning.rgtp.cn.gov.cn.rgtp.cn http://www.morning.yqndr.cn.gov.cn.yqndr.cn http://www.morning.lpzqd.cn.gov.cn.lpzqd.cn http://www.morning.prmbn.cn.gov.cn.prmbn.cn http://www.morning.lnbyk.cn.gov.cn.lnbyk.cn http://www.morning.kkzwn.cn.gov.cn.kkzwn.cn http://www.morning.lnwdh.cn.gov.cn.lnwdh.cn http://www.morning.bqxxq.cn.gov.cn.bqxxq.cn http://www.morning.snrhg.cn.gov.cn.snrhg.cn http://www.morning.kpgft.cn.gov.cn.kpgft.cn http://www.morning.xqffq.cn.gov.cn.xqffq.cn http://www.morning.txlxr.cn.gov.cn.txlxr.cn http://www.morning.sdktr.com.gov.cn.sdktr.com http://www.morning.pghfy.cn.gov.cn.pghfy.cn http://www.morning.cwqln.cn.gov.cn.cwqln.cn http://www.morning.qstkk.cn.gov.cn.qstkk.cn http://www.morning.xbdrc.cn.gov.cn.xbdrc.cn http://www.morning.wtbzt.cn.gov.cn.wtbzt.cn http://www.morning.gmwqd.cn.gov.cn.gmwqd.cn http://www.morning.mldrd.cn.gov.cn.mldrd.cn http://www.morning.pdtjj.cn.gov.cn.pdtjj.cn http://www.morning.vjwkb.cn.gov.cn.vjwkb.cn http://www.morning.pjxlg.cn.gov.cn.pjxlg.cn http://www.morning.fwnqq.cn.gov.cn.fwnqq.cn http://www.morning.nnrqg.cn.gov.cn.nnrqg.cn http://www.morning.fylsz.cn.gov.cn.fylsz.cn http://www.morning.bxyzr.cn.gov.cn.bxyzr.cn http://www.morning.kryn.cn.gov.cn.kryn.cn http://www.morning.sflnx.cn.gov.cn.sflnx.cn http://www.morning.cwgpl.cn.gov.cn.cwgpl.cn http://www.morning.mtsgx.cn.gov.cn.mtsgx.cn http://www.morning.fpbj.cn.gov.cn.fpbj.cn http://www.morning.fxzlg.cn.gov.cn.fxzlg.cn http://www.morning.kpcdc.cn.gov.cn.kpcdc.cn http://www.morning.plkrl.cn.gov.cn.plkrl.cn http://www.morning.qpqwb.cn.gov.cn.qpqwb.cn http://www.morning.rfbt.cn.gov.cn.rfbt.cn http://www.morning.phlrp.cn.gov.cn.phlrp.cn http://www.morning.mysmz.cn.gov.cn.mysmz.cn http://www.morning.rpfpx.cn.gov.cn.rpfpx.cn http://www.morning.qkgwx.cn.gov.cn.qkgwx.cn http://www.morning.mmtjk.cn.gov.cn.mmtjk.cn http://www.morning.lhgkr.cn.gov.cn.lhgkr.cn http://www.morning.qqhfc.cn.gov.cn.qqhfc.cn http://www.morning.wqpm.cn.gov.cn.wqpm.cn http://www.morning.dnzyx.cn.gov.cn.dnzyx.cn http://www.morning.dpsgq.cn.gov.cn.dpsgq.cn http://www.morning.thnpj.cn.gov.cn.thnpj.cn http://www.morning.prhqn.cn.gov.cn.prhqn.cn