docker tutorial (1) - Quick Start

docker Notes (1) --docker installation, image acquisition, start containers, remove the container

First, install

Docker official document
finishing process is simple, according to official documents

  1. Mac download package from Docker Hub

  2. Run disk mirroring, copying Docker to the application

  3. Docker Docker find the icon to run the application

  4. docker operating status can be seen in his system status bar

  1. After a successful run Docker can be used in Terminal, icon command:docker version

Second, the command

1, get a mirror

Detailed command

docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]

Use docker pull helpView Help

Simple to use:

docker pull ubuntu:18.04
This command will automatically default to docker Hubpulling named ubuntu, labeled: 18.04 in the ubuntusystem image, do not use the label automatically latest
command appears similar after completion:

$ docker pull ubuntu:18.04

18.04: Pulling from library/ubuntu
bf5d46315322: Pull complete
9f13e0ac480c: Pull complete
e8988b5b3097: Pull complete
40af181810e7: Pull complete
e6f7c7e5c03e: Pull complete
Digest: sha256:147913621d9cdea08853f6ba9116c2e27a3ceffecf3b492983ae97c3d643fbbe
Status: Downloaded newer image for ubuntu:18.04

The following excerpt Address: [] Hierarchical Storage :

  • Because the operating system image contains the complete root file system, the volume is often large, so Docker design, take full advantage of Union FS technology, it is designed as a tiered storage architecture. Mirroring is only a virtual concept, its practical expression is not composed of one file, but by a set of file system components, or by a coalition of multi-layer file system.
  • Mirror building will be constructed layers, the first layer after layer of the foundation, floor operations before deleting the file, before the actual file is not really deleted one, but only at the current level has been marked for the file delete. When the final container to run, though not seen this document, but in fact the file will always follow the mirror.
  • When building the mirror, you need to be extra careful, try each layer of the layer containing only thing you need to add any extra things to be cleared away before the end of the layer build.

It is composed of a multilayer mirror storage. Download is a layer of to download, not a single file. Download process before the given ID 12 of each layer. And after the download is complete, the mirror gives a complete summary of the sha256 to ensure consistency download.

2、以镜像为基础,启动并运行一个容器

docker run -it --rm ubuntu:18.04 bash
参数:
-it: 两个参数: -i 使用交互式操作, -t 终端启动
--rm: 在退出容器之后,删除容器
ubuntu:18.04:容器名称和标签
bash: 使用bash shell进入系统

已经运行的镜像,可以通过container查看

因为之前的运行使用了参数--rm, 会导致在exit后自动删除container, 所以在使用命令前,请新开一个terminal

$ docker container ls # 查看正在运行中的容器
$ docker container ls -a # 查看所有容器,包括正在运行&&停止运行的容器

3、停止容器

通过docker container ls 能查看到的容器, 可以通过停止容器命令 docker container stop <container_name>
由于之前的启动命令没有指定容器名称(container_name),可以使用docker随机分配的容器名进行操作。

这里分配的容器名称为:goofy_vaughan

$ docker container stop goofy_vaughan

除了使用名称,也可以使用CONTAINER_ID进行操作, 而且不需要输入全部字符4424419a386e ,只需要输入大于等于三个字符442并且能表明容器唯一就可以了。

4、删除容器

停止容器后容器并没有被删除,
使用:docker container ls 没有出现的容器,使用docker container ls -a查看到了,就说明容器被停止了,删除容器的命令:docker container rm <container_name>
同停止容器一样,container_name可以使用CONTAINER_ID代替

本文参考资料

Docker 官方文档
Docker — 从入门到实践

Guess you like

Origin www.cnblogs.com/zeryter/p/11296755.html
Recommended