docker in action 笔记之第三章(软件安装的简化)

软件安装的简化

  • 选择所需的软件
  • 使用docker hub查找和安装软件
  • 从其他来源安装软件
  • 了解文件系统的隔离
  • 镜像和文件系统的分离
  • 使用分层镜像得 特点
  1. 学习要点归纳

    • 安装docker镜像的三种方式
      • docker hub和其他注册服务器
      • 使用docker savedocker load
      • 使用Dockerfile构建镜像
  2. 环境

    • win10+虚拟机(centos7)
    • centos7 + docker1.13
    • 修改了仓库的默认地址为registry.docker-cn.com
  3. 笔记

    • 仓库名:
      • 三部分组成:仓库名+用户名+容器短名,用/隔开
      • quay.io/dockerinaction/ch3_hello_registry
    • 标签:
      • 如java的jdk有相应的版本,标签就是用来唯一确定一类软件中的哪一个软件。通常与仓库名结合使用
      • 仓库名:函数名->唯一确定具体软件
      • docker pull registry.docker-cn.com/library/centos:7(拉取centos7镜像)
      • docker pull registry.docker-cn.com/library/centos:6(拉取centos6镜像)
      • docker pull registry.docker-cn.com/library/centos(缺省版本号,默认拉取latest)
      • docker tag给镜像换标签
    • 查找、安装软件
      • 镜像的两种发布方式:
        • 使用命令行来发布独立系统的镜像(docker push)
        • 公开Dockerfile,并使用Docker Hub的持续构建
      • 私有docker hub的注册服务器、推送镜像在私有注册服务器、登录授权等在本书的第7章介绍。
      • 查找镜像
        • docker search <应用名>
        • docker search centos(搜索docker hub索引库,看到类似github的打星等相关信息)
      • 删除镜像
        • docker rmi <镜像名>+版本号
        • 版本号缺省,默认删除latest
      • 一个例子:
        • docker run -it --rm dockerinaction/ch3_ex2_hunt(提示输入密码,若密码错误,提示寻找密码线索)
        • docker search dockerinaction/* (根据输出的信息,找到相关镜像,启动容器寻找答案)
      • 使用代替服务器
        • 注册服务器地址完成格式:[registyhost/][username/]NAME[:tag]
        • docker pull nginx(使用默认注册服务器地址下载)
        • docker pull registry.docker-cn.com/library/centos:7(使用代替服务器下载)
      • 镜像文件的导入导出
        • docker pull busybox:latest
        • docker save -o myfile.tar busybox:latest
          • -o参数,可制定输出文件为.tar
          • 使用docker save --help查看更多
        • docker rmi busybox
        • dcoker load < myfile.tardcoker load -i myfile.tar
    • 镜像层实战
      • 镜像是由不同的镜像层组成,可以说镜像是很多个镜像层的集合。
      • 例子:
        • docker pull dockerinaction/ch3_myapp
        • docker pull dockerinacton/ch3_myotherapp
        • 拉取镜像的时候是一层一层的下载,只有安装了上层的所有依赖,完成上层的安装,下一层才能开始安装。ch3_myapp和ch3_myotherapp都依赖于镜像java:6,先拉取ch3_myapp再拉取ch3_myotherapp时,可以发现后者的拉取速度要远大于前者。原因是镜像层可以复用,拉取ch3_myapp时已经拉取了java:6层,再docker pull ch3_myotherapp时,就不需要重新拉取java:6
        • 拉取镜像时,相同的镜像层可以复用,只需要在第一次pull的时候下载安装,以后就可以复用。
        • docker images,看到java:6、ch3_myapp、ch3_myotherapp三个镜像
      • 分层关系
      • 容器文件系统抽象和隔离
        • Union文件系统
        • Linux MNT命名空间
        • chroot
      • 分层文件系统及其工具的优点
        • 公共层只需要安装一次
        • 分层提供了依赖管理和隔离的工具
        • 便于构建专业的软件
      • Union文件系统的不足
        • 不同的文件系统有不同的文件属性、大小、名称和字符。Union需要在不同的文件规则之间进行转换
        • Union使用写时复制的模式,内存映射文件的实现较为困难
  4. 总结

    • docker用户可以使用仓库名称来确定他们想通过docker安装的软件
    • docker Hub是默认的注册服务器,可以通过网站或docker命令行工具在docker Hub上找到需要的软件
    • docker命令行工具可以很方便地通过其他注册服务器或其他形式来分发安装软件
    • 镜像仓库配置中会包括注册服务器的主机信息
    • docker load 和docker save命令可以将tar档案文件用来加载和保存镜像
    • 分发一个项目的Dockerfile可简化用户机器上构建镜像的过程
    • 镜像通常和其他镜像都有父子的关联。这些关系构成分层。当我们说,我们已经安装了一个镜像,我们是说已经安装了一个目录镜像,及其依赖的每个镜像层
    • 使用分层构建镜像,可重用分层,并可节省分发带宽和机器上的存储空间。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Docker-in-Action.pdf In 2011, I started working at Amazon.com. In that first week my life was changed as I learned how to use their internal build, dependency modeling, and deployment tool- ing. This was the kind of automated management I had always known was possible but had never seen. I was coming from a team that would deploy quarterly and take 10 hours to do so. At Amazon I was watching rolling deployments push changes I had made earlier that day to hundreds of machines spread all over the globe. If big tech firms had an engineering advantage over the rest of the corporate landscape, this was it. Early in 2013, I wanted to work with Graphite (a metrics collection and graphing suite). One day I sat down to install the software and start integrating a personal proj- ect. At this point I had several years of experience working with open source applica- tions, but few were as dependent on such large swaths of the Python ecosystem. The installation instructions were long and murky. Over the next several hours, I discov- ered many undocumented installation steps. These were things that might have been more obvious to a person with deeper Python ecosystem knowledge. After pouring over several installation guides, reading through configuration files, and fighting an epic battle through the deepest parts of dependency hell, I threw in the towel. Those had been some of the least inspiring hours of my life. I wanted nothing to do with the project. To make matters worse, I had altered my environment in a way that was incompatible with other software that I use regularly. Reverting those changes took an embarrassingly long time. I distinctly remember sitting at my desk one day in May that year. I was between tasks when I decided to check Hacker News for new ways to grow my skillset. Articles about a technology called Docker had made the front page a few times that week. That evening I decided to check it out. I hit the site and had the software installed within a few minutes. I was running Ubuntu on my desktop at home, and Docker only had two dependencies: LXC and the Linux kernel itself. Licensed to Stephanie Bernal <nordicka.n@gmail.com> PREFACE xiv Like everyone else, I kicked the tires with a “Hello, World” example, but learned little. Next I fired up Memcached. It was downloaded and running in under a minute. Then I started WordPress, which came bundled with its own M y SQL server. I pulled a couple different Java images, and then Python images. Then my mind flashed back to that terrible day with Graphite. I popped over to the Docker Index (this was before Docker Hub) and did a quick search. The results came back, and there it was. Some random user had created a Graphite image. I pulled it down and created a new container. It was running. A simple but fully configured Graphite server was running on my machine. I had accomplished in less than a minute of download time what I had failed to do with several hours a few months earlier. Docker was able to demonstrate value with the simplest of examples and minimum effort. I was sold. Over the next week, I tried the patience of a close friend by struggling to direct our conversations toward Docker and containers. I explained how package management was nice, but enforcing file system isolation as a default solved several management problems. I rattled on about resource efficiency and provisioning latency. I repeated this conversation with several other colleagues and fumbled through the container story. Everyone had the same set of tired questions, “Oh, it’s like virtualization?” and “Why do I need this if I have virtual machines?” The more questions people asked, the more I wanted to know. Based on the popularity of the project, this is a story shared by many. I began including sessions about Docker when I spoke publicly. In 2013 and 2014, only a few people had heard of Docker, and even fewer had actually tried the software. For the most part, the crowds consisted of a few skeptical system administrator types and a substantial number of excited developers. People reacted in a multitude of ways. Some were pure rejectionists who clearly preferred the status quo. Others could see problems that they experienced daily solved in a matter of moments. Those peo- ple reacted with an excitement similar to mine. In the summer of 2014, an associate publisher with Manning called me to talk about Docker. After a bit more than an hour on the phone he asked me if there was enough content there for a book. I suggested that there was enough for a few books. He asked me if I was interested in writing it, and I became more excited than I had been for some time. That fall I left Amazon.com and started work on Docker in Action. Today, I'm sitting in front of the finished manuscript. My goal in writing this book was to create something that would help people of mixed backgrounds get up to speed on Docker as quickly as possible, but in such a way that they understand the underlying mechanisms. The hope is that with that knowledge, readers can under- stand how Docker has been applied to certain problems, and how they might apply it in their own use-cases.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值