docker官方 快速开始教程:docs.docker.com/get-started
Docker concepts🔗
Docker is a platform for developers and sysadmins to build, run, and share applications with containers. The use of containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is.
Containerization is increasingly popular because containers are:
- Flexible: Even the most complex applications can be containerized.
- Lightweight: Containers leverage and share the host kernel, making them much more efficient in terms of system resources than virtual machines.
- Portable: You can build locally, deploy to the cloud, and run anywhere.
- Loosely coupled: Containers are highly self sufficient and encapsulated, allowing you to replace or upgrade one without disrupting others.
- Scalable: You can increase and automatically distribute container replicas across a datacenter.
- Secure: Containers apply aggressive constraints and isolations to processes without any configuration required on the part of the user.
Docker概念
Docker是一个供开发人员和系统管理员使用容器构建、运行和共享应用程序的平台。使用容器部署应用程序称为容器化。
Docker有以下特点
- 灵活:即使是最复杂的应用程序也可以容器化。
- 轻量级:容器利用并共享主机内核,使它们在系统资源方面比虚拟机效率更高。
- 可移植性:您可以在本地构建、部署到云,并在任何地方运行。
- 松散耦合:容器是高度自给自足和封装的,允许您替换或升级一个容器,而不会中断其他容器。
- 可伸缩性:您可以在数据中心增加并自动分发容器副本。
- 安全性:容器对进程应用严格的约束和隔离,而用户不需要任何配置。
Images and containers
Fundamentally, a container is nothing but a running process, with some added encapsulation features applied to it in order to keep it isolated from the host and from other containers. One of the most important aspects of container isolation is that each container interacts with its own private filesystem; this filesystem is provided by a Docker image. An image includes everything needed to run an application - the code or binary, runtimes, dependencies, and any other filesystem objects required.
镜像和容器
从根本上说,容器不过是一个正在运行的进程,它应用了一些附加的封装特性,以便将它与主机和其他容器隔离开来。容器隔离的一个最重要的方面是,每个容器都与自己的私有文件系统交互;这个文件系统由Docker映像提供。镜像包含运行应用程序所需的所有内容—代码或二进制文件、运行时、依赖项以及所需的任何其他文件系统对象。
Containers and virtual machines
A container runs natively on Linux and shares the kernel of the host machine with other containers. It runs a discrete process, taking no more memory than any other executable, making it lightweight.
By contrast, a virtual machine (VM) runs a full-blown “guest” operating system with virtual access to host resources through a hypervisor. In general, VMs incur a lot of overhead beyond what is being consumed by your application logic.
容器和虚拟机
容器在Linux上本机运行,并与其他容器共享主机的内核。它运行一个离散的进程,占用的内存不比任何其他可执行文件多,因此它很轻。
相比之下,虚拟机(VM)运行一个完整的“guest” 操作系统,通过虚拟机监控程序对主机资源进行虚拟访问。一般来说,vm除了应用程序逻辑所消耗的开销之外,还会产生很多开销。
Test Docker version 🔗
After you’ve successfully installed Docker Desktop, open a terminal and run
docker --version
to check the version of Docker installed on your machine.
查看docker版本
$ docker --version
Docker version 19.03.5, build 633a0ea
验证docker已经成功安装
Test Docker installation🔗
- Test that your installation works by running the hello-world Docker image:
- 通过运行一个HelloWord镜像来验证你的docker已经完成安装
$ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. ...
- Run
docker image ls
to list thehello-world
image that you downloaded to your machine.
- 运行
docker image ls
列出你的机器上已经下载的镜像
- List the
hello-world
container (spawned by the image) which exits after displaying its message. If it is still running, you do not need the--all
option:
-
列出你的所有容器
$ docker container ls --all CONTAINER ID IMAGE COMMAND CREATED STATUS 54f4984ed6a8 hello-world "/hello" 20 seconds ago Exited (0) 19 seconds ago
Conclusion🔗
At this point, you’ve installed Docker Desktop on your development machine, and ran a quick test to ensure you are set up to build and run your first containerized application.
结论
到此为止你就已经完成了你的docker安装完成的验证,而且运行了你的第一个容器hello-world