Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create app with docker

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article focuses on "how to use docker to create app", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to create app with docker.

Docker-app orchestrates the docker container as a bundle, named the application application. You want to package a set of docker containers as an application for distribution.

Enable the app plug-in

App is an experience feature, which is not enabled by default, and the minimum version is 19.03, so make sure that the docker engine is not lower than this version first.

Edit ~ / .docker/config.json, add:

{"experimental": "enabled", "debug": true}

Check:

Docker...app* Docker Application (Docker Inc., v0.8.0) builder Manage buildsbuildx* Build with BuildKit (Docker Inc., v0.3.1-tp-docker) checkpoint Manage checkpoints...

The instruction of the tag * is the experience feature instruction.

# docker app versionVersion: v0.8.0Git commit: 7eea32bBuilt: Wed Nov 13 07:28:05 2019OS/Arch: linux/amd64Experimental: offRenderers: noneInvocation Base Image: docker/cnab-app-base:v0.8.0 create app

Initialize a docker application in the current working directory.

# dockerapp init myapp# tree.. └── myapp.dockerapp ├── docker-compose.yml ├── metadata.yml └── parameters.yml1 directory, 3 files

By default, a project directory is created in the working directory that contains three files:

Choreography files for docker-compose.yml services basic configuration files for metadata.yml projects variables referenced by parameters.yml service compose

Create a single-file project: it is well known that it is much more troublesome to distribute a directory than to distribute a single file, so docker-app supports the consolidation of the application's project files into a separate file.

# docker app init demo-single-file# ll-rw-r--r--. 1 root root 508 Dec 2 07:13 demo.dockerapp

The project file is not unchangeable after it is created. You can convert the application of the directory format to a single file at any time:

Docker app merge myapp

Conversely, the bill file project is converted to a directory format:

Docker app split myapp editing service

Vi myapp.dockerapp/docker-compose.yml

Version: "3.6" services: {" nginx ": {" image ":" nginx "}} install app

App needs to be run in a swarm environment, and the simplest test environment is to run in a stand-alone environment: docker swarm init-- advertise-addr= your IP address

# docker app install myapp# docker service lsID NAME MODE REPLICAS IMAGE PORTSi2ceu8f82bsh myapp_nginx replicated 1 nginx:latest# docker app lsINSTALLATION APPLICATION LAST ACTION RESULT CREATED MODIFIED REFERENCEmyapp myapp (0.1.0) install success 6 seconds 4 seconds View Service

Use the render subcommand to view the service orchestration of the docker application:

# docker app render myappversion: "3.6" services: nginx: deploy: replicas: 2 image: nginx

If the myapp project file is not in the current directory, like the image, the docker engine will first go to the central warehouse to pull it.

Use parameter

Modify the parameters.json file:

"DEPLOY_REPLICAS": 5

Modify the docker-compose reference to this variable:

Version: "3.6" services: {"nginx": {"image": "nginx", "deploy": {"replicas": "${DEPLOY_REPLICAS}"}

View services:

# docker app render myappversion: "3.6" services: nginx: deploy: replicas: 5 image: nginx

Multi-level variables: the parameter configuration file is in yaml format, which is easy to think of-- you can use multi-level parameter names so that different variables can be grouped.

Deploy: replicas: 2

In the corresponding compose:

"replicas": "${deploy.replicas}"

Variables are not allowed in image.

Update app

Upgrade can only update values in variables.

Upgrade does not reload app's configuration file and can only pass in the key value of the variable through-- set or-s.

Perform an update:

# docker app upgrade myapp-s DEPLOY_REPLICAS=2Updating service myapp_nginx (id: t9n7hcic2ek42qhn35kyfh3lj) Application "myapp" upgraded on context "default" # docker service lsID NAME MODE REPLICAS IMAGE PORTSud4sms7cx9yx myapp_nginx replicated 2 nginx:latest Delete App docker app uninstall myapp publish App docker login 192.168.33.10:5000docker app push myapp

Login succeeded

Modified name: 192.168.33.10:5000/library/myapp in metadata

Insecure-registries has been configured.

But failed:

# docker app push myapp192.168.33.10:5000/library/myapp:0.1.0-invocfixing up "192.168.33.10:5000/library/myapp:0.1.0" for push: failed to resolve "192.168.33.10:5000/library/myapp:0.1.0-invoc" Push the image to the registry before pushing the bundle: failed to do request: Head https://192.168.33.10:5000/v2/library/myapp/manifests/0.1.0-invoc: http: server gave HTTP response to HTTPS client

It doesn't seem to work to find https,insecure-registries.

Try not to modify the name in metadata and use the tag parameter on the command line:

# docker app push myapp-t 192.168.33.10:5000/library/myapp192.168.33.10:5000/library/myapp:latest-invocfixing up "192.168.33.10:5000/library/myapp:latest" for push: failed to resolve "192.168.33.10:5000/library/myapp:latest-invoc", push the image to the registry before pushing the bundle: failed to do request: Head https://192.168.33.10:5000/v2/library/myapp/manifests/latest-invoc: http: server gave HTTP response to HTTPS client

-you can see the image of the specified tag in docker images, but push still fails

Repositories using the https protocol still fail.

For private service, there is no solution for the time being, and there are not many documents on the official website.

It is often pushed to the central warehouse through:

Docker app push myapp-t pollyduan/myapp

The red and blue log flashes and looks normal. But the end is cruel:

Fixing up "docker.io/pollyduan/myapp:latest" for push: failed commit on ref "manifest-sha256:f5dc44557f1d666381791c3d01300d64899ba7b74dc26f4d681bd1827caf61ca": no response

Log in to hub.docker.com to check that the image exists.

At this point, I believe you have a deeper understanding of "how to create app with docker". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report