导读:预备知识虽然我们接下来还是会介绍很多概念,但是最好还是提前了解什么是Docker,和为什么你会使用Docker。我们假设你对下面这些知识比较熟...
预备知识
虽然我们接下来还是会介绍很多概念,但是最好还是提前了解什么是Docker,和为什么你会使用Docker。
我们假设你对下面这些知识比较熟悉:
- IP地址和端口
- 虚拟机
- 编辑配置文件
- 代码依赖和代码构建的基本认识
- 计算机资源的使用指标,如:CPU使用率,RAM的使用情况等
对容器的简短的解释
镜像是轻量的,独立的,可执行的包,并且包含了软件运行需要的所有东西,包括:代码,运行环境,各种库,环境变量,配置文件等。
容器是一个镜像的运行实例——也就是镜像被加载到内存,并且真的被执行之后。默认情况下,容器和宿主机是完全隔离的,最多也只会在配置了的情况下,使用宿主机的hosts文件和端口。
容器会把应用直接运行在宿主机的内核中,这样会比虚拟机有更好的性能,因为虚拟机只能通过hypervisor(超级监督者)来间接的使用宿主机资源的虚拟权限。容器可以获得原生的资源使用权限,每个都运行在独立的进程中,不需要额外的内存。
虚拟机示意图
注意看每个OS层,虚拟机上运行着客户机的操作系统。这是资源集中的,结果也就是磁盘镜像,应用状态都和宿主机耦合起来,包括宿主机的设置,系统安装的依赖,系统的安全补丁,还有其他一些容易忽略的小细节。
容器示意图
容器共享一个内核,而且要想制作一个容器镜像,只需要有程序的执行文件和相关的依赖就可以了,这些都不需要安装到宿主机。你可以使用docker ps来管理这些进程,很类似用ps操作系统的原生的进程。最后需要注意的是,容器已经包含了程序运行的所有依赖,不需要再有任何配置;所以一个容器化的应用就是可以“runs anywhere”(在任何地方运行)。
设置
在设置之前,请先确保你已经暗转挂了最新版本的Docker。安装
注意:这份文档需要版本不低于1.13。
如果安装完了,可以尝试运行docker run hello-world:
- ~ docker run hello-world
- Unable to find image 'hello-world:latest' locally
- latest: Pulling from library/hello-world
- b04784fba78d: Pull complete
- Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
- Status: Downloaded newer image for hello-world:latest
- Hello from Docker!
- This message shows that your installation appears to be working correctly.
- To generate this message, Docker took the following steps:
- 1. The Docker client contacted the Docker daemon.
- 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
- 3. The Docker daemon created a new container from that image which runs the
- executable that produces the output you are currently reading.
- 4. The Docker daemon streamed that output to the Docker client, which sent it
- to your terminal.
- To try something more ambitious, you can run an Ubuntu container with:
- $ docker run -it ubuntu bash
- Share images, automate workflows, and more with a free Docker ID:
- https:
- For more examples and ideas, visit:
- https:
在看看版本是否满足要求,使用docker --version:
- ~ docker --version
- ocker version 17.05.0-ce-rc1, build 2878a85
微信扫码关注订阅号IT开发前线,获取更多精彩内容