Docker 学习系列(一): Hello Docker!
Docker 基础介绍及常用命令
简介
Docker 使用 Go 语言开发,基于内核的 cgroup, namespace 以及 OverlayFS 类的 UnionFS 等技术,对进程进行封装隔离,属于操作系统层面的虚拟化技术。
基本概念:
镜像 (Image)
官方文档的描述如下:
The are two important principles of images:
- Images are immutable. Once an image is created, it can’t be modified. You can only make 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.
镜像本身是一个特殊的文件系统,除了提供容器运行时所需的环境外,镜像本身不包含任何动态数据,并且采用分层存储的架构来缩小本身的体积。
容器 (Container)
官方文档描述如下:
Containers are isolated processes for each of your app’s compoents.
Containers are:
- 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 other.
- Portable: Containers can run anywhere! The container that runs on your develpment machine will work the same way in a data center or anywhere in the cloud!
容器是镜像运行时的实体,其允许被创建、启动、停止、删除等操作。容器在运行时会以镜像为基础层,在其上创建一个当前容器的存储层,该层的生命周期与当前容器绑定。
仓库 (Repository)
官方文档描述如下:
A registry is a centralized location that stores and manages container images, whereas a repository is collection of related container images within a registry.
一个 Docker Registry 中可以包含多个仓库(Repository);每个仓库可以包含多个标签(Tag);每个 Tag 对应一个镜像。
常用操作
常用操作请参考: docker CLI Cheat Sheet,以下仅列出命令, 具体选项请使用 help
或搜索引擎获取。
镜像:
- 获取镜像:
docker pull
- 列出镜像:
docker image ls
- 镜像构建:
docker build
- 推送镜像:
docker push
- 获取镜像 commit 历史:
docker history
容器:
- 创建容器:
docker run
- 停止容器:
docker stop
- 启动容器:
docker start
- 持久化容器修改:
docker commit
参考
Docker 官方文档: click
Docker 从入门到实践: click