日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Docker App应用

發(fā)布時間:2023/11/28 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Docker App应用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Docker App應(yīng)用

這是一個實驗特性。

實驗性功能提供了對未來產(chǎn)品功能的早期訪問。這些特性僅用于測試和反饋,因為它們可能在沒有警告的情況下在不同版本之間更改,或者可以從將來的版本中完全刪除。在生產(chǎn)環(huán)境中不得使用實驗性功能。

Docker不支持實驗特性。

要在Docker CLI中啟用實驗性功能,請編輯config.json文件并將“實驗”設(shè)置為“已啟用”。

要從Docker桌面菜單啟用實驗功能,請單擊設(shè)置(macOS上的首選項)>命令行,然后啟用啟用啟用實驗功能切換。單擊應(yīng)用并重新啟動。

有關(guān)Docker CLI中當前實驗功能的列表,請參閱Docker CLI實驗功能。

Overview

Docker App是一個CLI插件,它引入了一個頂級的Docker App命令,為應(yīng)用程序帶來容器體驗。下表比較了Docker容器和Docker應(yīng)用程序。

有了Docker應(yīng)用程序,整個應(yīng)用程序現(xiàn)在可以像管理圖像和容器一樣輕松。例如,Docker App允許使用Docker App命令構(gòu)建、驗證和部署應(yīng)用程序。甚至可以利用安全的供應(yīng)鏈功能,例如簽名的推拉操作。

注:docker應(yīng)用程序可與docker 19.03或更高版本配合使用。

本指南將引導了解兩種情況:

從頭開始初始化并部署新的Docker應(yīng)用程序項目。

將現(xiàn)有的Compose應(yīng)用程序轉(zhuǎn)換為Docker應(yīng)用程序項目(稍后在beta過程中添加)。

第一個場景描述Docker應(yīng)用程序的基本組件以及工具和工作流。

從頭開始初始化并部署新的Docker應(yīng)用程序項目

本節(jié)介紹創(chuàng)建新Docker應(yīng)用程序項目的步驟,熟悉工作流和最重要的命令。

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節(jié)點在Swarm模式下運行。還需要包含appcli插件的Docker CLI的最新版本。

根據(jù)Linux發(fā)行版和安全上下文,可能需要在命令前面添加sudo。

初始化新的空項目

docker app init命令用于初始化新的docker應(yīng)用程序項目。如果運行它,它會初始化一個新的空項目。如果把它指向一個現(xiàn)有的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: {}


Default application parameters - equivalent to parameters.yml.

你的文件可能更詳細。

請注意,這三個部分中的每一部分都由一組三個破折號(“–”)分隔開。快速描述每個部分。

文件的第一部分指定標識元數(shù)據(jù),例如名稱、版本、描述和維護者。它接受key-value
pairs。文件的這一部分可以是一個單獨的文件,名為metadata.yml

文件的第二部分描述了應(yīng)用程序。

它可以是一個名為docker的docker-compose.yml.

最后一節(jié)指定應(yīng)用程序參數(shù)的默認值。它可以是一個名為parameters.yml

填充項目

本節(jié)介紹如何編輯project YAML文件,以便它運行一個簡單的web應(yīng)用程序。

使用首選的編輯器編輯hello-world.dockerapp YAML文件并使用以下信息更新應(yīng)用程序部分:

version: “3.6”

services:

hello:

image: hashicorp/http-echocommand: ["-text",

“${hello.text}”]

ports:- ${hello.port}:5678

Update the Parameters section to the following:

hello:

port: 8080

text: Hello world!

The sections of
the YAML file are currently order-based. This means it’s important they remain
in the order we’ve explained, with the metadata section being first, the
app section being second, and the parameters section being last.
This may change to name-based sections in future releases.

Save the
changes.

The application is updated to run a
single-container application based on the hashicorp/http-echo web server image. This image has it execute a single command that
displays some text and exposes itself on a network port.

Following best practices, the
configuration of the application is decoupled from the application itself using
variables. In this case, the text displayed by the app and the port on which it
will be published are controlled by two variables defined in the Parameters section of the file.

Docker App provides the inspect subcommand to provide a prettified
summary of the application configuration. It is a quick way to check how to
configure the application before deployment, without having to read the Compose file. It’s important to note that the
application is not running at this point, and that the inspect operation inspects the configuration file(s).

$ docker app inspect hello-world.dockerapp

hello-world 0.1.0

Service (1) Replicas Ports Image


hello 1 8080
hashicorp/http-echo

Parameters (2) Value


hello.port 8080

hello.text Hello world!

docker app inspect operations fail if the Parameters section doesn’t specify a default value for every parameter expressed in
the app section.

The application
is ready to be validated and rendered.

Validate the app🔗

Docker App provides the validate subcommand to check syntax and other
aspects of the configuration. If the app passes validation, the command returns
no arguments.

$ docker app validate hello-world.dockerapp

Validated “hello-world.dockerapp”

docker app validate operations
fail if the Parameters
section doesn’t specify a default value for every parameter expressed in the
app section.

As the validate operation has returned no
problems, the app is ready to be deployed.

Deploy the app

There are several options for deploying a Docker App project.

Deploy as a native Docker App application
Deploy as a Compose app application
Deploy as a Docker Stack application

All three options are discussed, starting with deploying as a native Docker App application.

Deploy as a native Docker App

The process for deploying as a native Docker app is as follows:

Use docker app install to deploy the application.

Use the following command to deploy (install) the application.

$ docker app install hello-world.dockerapp --name my-appCreating network my-app_defaultCreating service my-app_helloApplication “my-app” installed on context “default”

By default, docker app uses the current context
to run the installation container and as a target context to deploy the application. You can override the second context using the flag --target-context or by using the environment variable DOCKER_TARGET_CONTEXT. This flag is also available for the commands status, upgrade, and uninstall.

$ docker app install hello-world.dockerapp --name my-app --target-context=my-big-production-clusterCreating network my-app_defaultCreating service my-app_helloApplication “my-app” installed on context “my-big-production-cluster”

Note: Two applications deployed on the same target context cannot share the same name, but this is valid if they are deployed on different target contexts.

You can check the status of the app with the docker app status command.

$ docker app status my-appINSTALLATION------------Name: my-appCreated: 35 secondsModified: 31 secondsRevision: 01DCMY7MWW67AY03B029QATXFFLast Action: installResult: SUCCESSOrchestrator: swarm APPLICATION-----------Name: hello-worldVersion: 0.1.0Reference: PARAMETERS----------hello.port: 8080hello.text: Hello, World! STATUS------ID NAME MODE REPLICAS IMAGE PORTSmiqdk1v7j3zk my-app_hello replicated 1/1 hashicorp/http-echo:latest *:8080->5678/tcp

The app is deployed using the stack orchestrator. This means you
can also inspect it using the regular docker stack commands.

$ docker stack lsNAME SERVICES ORCHESTRATORmy-app 1 Swarm

Now that the app is running, you can point a web browser at the DNS name or public IP of the Docker node on port 8080 and see the app. You must ensure traffic to port 8080 is allowed on the connection from your browser to your Docker host.

Now change the port of the application using docker app upgrade command.

$ docker app upgrade my-app --set hello.port=8181Upgrading service my-app_helloApplication “my-app” upgraded on context “default”

You can uninstall the app with docker app uninstall my-app.

Deploy as a Docker Compose app

The process for deploying as a Compose app comprises two major steps:

Render the Docker app project as a docker-compose.yml file.
Deploy the app using docker-compose up.

You need a recent version of Docker Compose to complete these steps.

Rendering is the process of reading the entire application configuration and outputting it as a single docker-compose.yml file.
This creates a Compose file with hard-coded values wherever a parameter was specified as a variable.

Use the following command to render the app to a Compose file called docker-compose.yml in the current directory.

$ docker app render --output docker-compose.yml hello-world.dockerapp

Check the contents of the resulting docker-compose.yml file.

$ cat docker-compose.ymlversion: "3.6"services: hello: command: - -text - Hello world! image: hashicorp/http-echo ports: - mode: ingress target: 5678 published: 8080 protocol: tcp

Notice that the file contains hard-coded values that were expanded based on the contents of the Parameters section of the project’s YAML file. For example, ${hello.text} has been expanded to “Hello world!”.

Note: Almost all the docker app commands propose the --set key=value flag to override a default parameter.

Try to render the application with a different text:

$ docker app render hello-world.dockerapp --set hello.text=“Hello whales!” version: "3.6"services: hello: command: - -text - Hello whales! image: hashicorp/http-echo ports: - mode: ingress target: 5678 published: 8080 protocol: tcp

Use docker-compose up to deploy the app.

$ docker-compose up --detachWARNING: The Docker Engine you’re using is running in swarm mode.

The application is now running as a Docker Compose app and should be reachable on port 8080 on your Docker host. You must ensure traffic to port 8080 is allowed on the connection form your browser to your Docker host.

You can use docker-compose down to stop and remove the application.

Deploy as a Docker Stack

Deploying the app as a Docker stack is a two-step process very similar to deploying it as a Docker Compose app.

Render the Docker app project as a docker-compose.yml file.
Deploy the app using docker stack deploy.

Complete the steps in the previous section to render the Docker app project as a Compose file and make sure you’re ready to deploy it as a Docker Stack. Your Docker host must be in Swarm mode.

$ docker stack deploy hello-world-app -c docker-compose.ymlCreating network hello-world-app_defaultCreating service hello-world-app_hello

The app is now deployed as a Docker stack and can be reached on port 8080 on your Docker host.

Use the docker stack rm hello-world-app command to stop and remove the stack. You must ensure traffic to port 8080 is allowed on the connection form your browser to your Docker host.

Push the app to Docker Hub

As mentioned in the introduction, docker app lets you manage entire applications the same way that you currently manage container images. For example, you can push and pull entire applications from registries like Docker
Hub with docker app push and docker app pull. Other docker app commands, such as install, upgrade, inspect, and render can be performed directly on applications while they are stored in a registry.

Push the application to Docker Hub. To complete this step, you need a valid Docker ID and you must be logged in to the registry to which you are pushing the app.

By default, all platform architectures are pushed to the registry. If you are pushing an official Docker image as part of your app, you may find your app bundle becomes large with all image architectures embedded.
To just push the architecture required, you can add the --platform flag.

$ docker login $ docker app push my-app --platform=“l(fā)inux/amd64” --tag /:0.1.0

Install the app directly from Docker Hub

Now that the app is pushed to the registry, try an inspect
and install command against it. The location of your app is different from the one provided in the examples.

$ docker app inspect myuser/hello-world:0.1.0hello-world 0.1.0 Service (1) Replicas Ports Image----------- -------- ----- -----hello 1 8080 myuser/hello-world@sha256:ba27d460cd1f22a1a4331bdf74f4fccbc025552357e8a3249c40ae216275de96 Parameters (2) Value-------------- -----hello.port 8080hello.text Hello world!

This action was performed directly against the app in the registry.

Now install it as a native Docker App by referencing the app in the registry, with a different port.

$ docker app install myuser/hello-world:0.1.0 --set hello.port=8181Creating network hello-world_defaultCreating service hello-world_helloApplication “hello-world” installed on context “default”

Test that the app is working.

The app used in these examples is a simple web server that displays the text “Hello world!” on port 8181, your app might be different.

$ curl http://localhost:8181Hello world!

Uninstall the app.

$ docker app uninstall hello-worldRemoving service hello-world_helloRemoving network hello world_defaultApplication “hello-world” uninstalled on context “default”

You can see the name of your Docker App with the docker stack ls command.

總結(jié)

以上是生活随笔為你收集整理的Docker App应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。