Docker App应用
这是一个实验特性。
实验性功能提供了对未来产品功能的早期访问。这些特性仅用于测试和反馈,因为它们可能在没有警告的情况下在不同版本之间更改,或者可以从将来的版本中完全删除。在生产环境中不得使用实验性功能。
Docker不支持实验特性。
要在Docker CLI中启用实验性功能,请编辑config.json文件并将“实验”设置为“已启用”。
要从Docker桌面菜单启用实验功能,请单击设置(macOS上的首选项)>命令行,然后启用启用启用实验功能切换。单击应用并重新启动。
有关Docker CLI中当前实验功能的列表,请参阅Docker CLI实验功能。
Overview
Docker App是一个CLI插件,它引入了一个顶级的Docker App命令,为应用程序带来容器体验。下表比较了Docker容器和Docker应用程序。
有了Docker应用程序,整个应用程序现在可以像管理图像和容器一样轻松。例如,Docker App允许使用Docker App命令构建、验证和部署应用程序。甚至可以利用安全的供应链功能,例如签名的推拉操作。
注:docker应用程序可与docker 19.03或更高版本配合使用。
本指南将引导了解两种情况:
从头开始初始化并部署新的Docker应用程序项目。
将现有的Compose应用程序转换为Docker应用程序项目(稍后在beta过程中添加)。
第一个场景描述Docker应用程序的基本组件以及工具和工作流。
从头开始初始化并部署新的Docker应用程序项目
本节介绍创建新Docker应用程序项目的步骤,熟悉工作流和最重要的命令。
l Prerequisites
l Initialize an empty new project
l Populate the project
l Validate the app
l Deploy the app
l Push the app to Docker Hub
l Install the app directly from Docker Hub
先决条件
你需要至少一个Docker节点在Swarm模式下运行。还需要包含appcli插件的Docker CLI的最新版本。
根据Linux发行版和安全上下文,可能需要在命令前面添加sudo。
初始化新的空项目
docker app init命令用于初始化新的docker应用程序项目。如果运行它,它会初始化一个新的空项目。如果把它指向一个现有的docker-compose.yml文件,它将基于合成文件初始化新项目。
使用以下命令初始化名为“hello world”的新空项目。
$ docker
app init --single-file hello-world
Created “hello-world.dockerapp”
该命令在当前目录中生成一个名为hello的hello-world.dockerapp。文件名的格式附加了“.dockerapp”。
$ ls
hello-world.dockerapp
If you run docker
app init without the --single-file flag, you get a new directory containing three YAML files. The name of
the directory is the name of the project with .dockerapp appended, and the three YAML files are:
docker-compose.yml
metadata.yml
parameters.yml
However, the --single-file option merges the three YAML files into a single YAML file with three
sections. Each of these sections relates to one of the three YAML files mentioned
previously: docker-compose.yml, metadata.yml, and parameters.yml. Using the --single-file option enables
you to share your application using a single configuration file.
Inspect the YAML
with the following command.
$ cat hello-world.dockerapp
Application metadata - equivalent to metadata.yml.
version: 0.1.0
name: hello-world
description:
Application services - equivalent to docker-compose.yml.
version: “3.6”
services: {}