Container (容器)
容器的特点:
- Self-contained. Each container has everything it needs to function with no reliance on any pre-installed dependencies on the host machine.
- Isolated. Since containers are run in isolation, they have minimal influence on the host and other containers, increasing the security of your applications.
- Independent. Each container is independently managed. Deleting one container won't affect any others.
- Portable. Containers can run anywhere! The container that runs on your development machine will work the same way in a data center or anywhere in the cloud!
容器和虚拟机的区别 Containers versus virtual machines (VMs)
Without getting too deep, a VM is an entire operating system with its own kernel, hardware drivers, programs, and applications. Spinning up a VM only to isolate a single application is a lot of overhead.
A container is simply an isolated process with all of the files it needs to run. If you run multiple containers, they all share the same kernel, allowing you to run more applications on less infrastructure.
Using VMs and containers together
Quite often, you will see containers and VMs used together. As an example, in a cloud environment, the provisioned machines are typically VMs. However, instead of provisioning one machine to run one application, a VM with a container runtime can run multiple containerized applications, increasing resource utilization and reducing costs.
容器相关命令
docker run -d -p 8080:80 docker/welcome-to-docker
docker ps
docker ps -a
docker stop
Image (镜像)
A container image is a standardized package that includes all of the files, binaries, libraries, and configurations to run a container.
镜像是各种文件的集合。
镜像的两个特点:
-
Images are immutable. Once an image is created, it can't be modified. You can only make a new image or add changes on top of it. (镜像是不可修改的)
-
Container images are composed of layers. Each layer represented a set of file system changes that add, remove, or modify files. (镜像由一些文件系统更改的层组成)
镜像相关命令
docker search docker/welcome-to-docker
docker pull docker/welcome-to-docker
docker image ls
docker images
docker image history docker/welcome-to-docker
docker image history docker/welcome-to-docker --no-trunc
注意:docker image history
命令是显示镜像的层,这个真没想到。
Registry
Registry 一般指 Docker Hub, 也可以有自建 Registry 。
Repository 是一些相关镜像的集合,可以理解为一个文件夹
镜像生成打标签相关命令
docker build -t <YOUR_DOCKER_USERNAME>/docker-quickstart .
docker tag <YOUR_DOCKER_USERNAME>/docker-quickstart <YOUR_DOCKER_USERNAME>/docker-quickstart:1.0
docker push <YOUR_DOCKER_USERNAME>/docker-quickstart:1.0
docker image tag
或 docker tag
可以给镜像打版本标签。
Docker Compose
在 Docker Compose 一节中介绍了运行 todo list 应用的过程,具体在 Docker 入门教程 中 Develop with containers
一节有叙述,这里偷懒不再写了。另外用到的命令记录下来,作个备忘:
docker compose up -d --build
docker compose down
docker compose down --volumes
至此,基本概念一篇草草结束!
作为初学者和使用者,阅读文档到此已经基本了解 Docker 的静态组成模块,并产生了包括本篇一共三篇笔记。
按顺序其他两篇传送门:
标签:container,image,基本概念,镜像,run,docker,Docker From: https://www.cnblogs.com/hexff/p/18371541