Docker 19.03 introduces an experimental feature: app, which is an instruction of docker, such as image, run, exec, swarm
Official documents: https://docs.docker.com/engine/reference/commandline/app/
Docker app arranges the docker container as a bundle, named application application. You want to package a set of docker containers as an application for distribution.
Enable app plug-in
app is an experience feature, which will not be enabled by default. The minimum version is 19.03, so first make sure the docker engine is not lower than this version.
Edit ~ /. docker/config.json, and add:
{ "experimental": "enabled", "debug": true }
Inspection:
docker ... app* Docker Application (Docker Inc., v0.8.0) builder Manage builds buildx* Build with BuildKit (Docker Inc., v0.3.1-tp-docker) checkpoint Manage checkpoints ...
The instructions marked with * are experience feature instructions.
# docker app version Version: v0.8.0 Git commit: 7eea32b Built: Wed Nov 13 07:28:05 2019 OS/Arch: linux/amd64 Experimental: off Renderers: none Invocation Base Image: docker/cnab-app-base:v0.8.0
Create app
Initialize a docker application in the current working directory.
# docker app init myapp # tree . . └── myapp.dockerapp ├── docker-compose.yml ├── metadata.yml └── parameters.yml 1 directory, 3 files
By default, a project directory is created in the working directory, which contains three files:
Choreography file of docker-compose.yml service Basic configuration file for metadata.yml project Variables referenced by parameters.yml service compose
Creating a single file project: as everyone knows, it is more difficult to distribute a directory than a single file. Therefore, docker app supports the integration of project files of an application into a single file.
# docker app init demo --single-file # ll -rw-r--r--. 1 root root 508 Dec 2 07:13 demo.dockerapp
The project file cannot be changed after creation. You can convert the application in directory format to a single file at any time:
docker app merge myapp
In turn, the single file project is converted to directory format:
docker app split myapp
Editorial services
vi myapp.dockerapp/docker-compose.yml
version: "3.6" services: { "nginx": { "image": "nginx" } }
Install app
- app needs to run in swarm environment. The simplest test environment is to run in a stand-alone environment: docker swarm init -- advertisement addr = your IP address
# docker app install myapp # docker service ls ID NAME MODE REPLICAS IMAGE PORTS i2ceu8f82bsh myapp_nginx replicated 1/1 nginx:latest # docker app ls INSTALLATION APPLICATION LAST ACTION RESULT CREATED MODIFIED REFERENCE myapp myapp (0.1.0) install success 6 seconds 4 seconds
View service
Use the render subcommand to view the service choreography of the docker application:
# docker app render myapp version: "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 pull it from the central warehouse.
Using parameters
Modify the parameters.json file:
"DEPLOY_REPLICAS": 5
Modify docker compose to reference this variable:
version: "3.6" services: { "nginx": { "image": "nginx", "deploy": { "replicas": "${DEPLOY_REPLICAS}" } } }
View services:
# docker app render myapp version: "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 you can group different variables.
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 the app's configuration file, it can only pass in the key value of the variable through -- set or - S.
Perform update:
# docker app upgrade myapp -s DEPLOY_REPLICAS=2 Updating service myapp_nginx (id: t9n7hcic2ek42qhn35kyfh2lj) Application "myapp" upgraded on context "default" # docker service ls ID NAME MODE REPLICAS IMAGE PORTS ud4sms7cx9yx myapp_nginx replicated 2/2 nginx:latest
Delete application
docker app uninstall myapp
Publishing application
docker login 192.168.33.10:5000 docker app push myapp
- login success
- Modified name in metadata: 192.168.33.10:5000 / library / myapp
- The secure registers are already configured
But it failed:
# docker app push myapp 192.168.33.10:5000/library/myapp:0.1.0-invoc fixing 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 seems that it's better to find https instead of secure registers.
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/myapp 192.168.33.10:5000/library/myapp:latest-invoc fixing 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
The warehouse using https protocol still fails.
For private servers, there is no way to solve it for the time being. There are not many documents on the official website.
It is usually pushed to the central warehouse through:
docker app push myapp -t pollyduan/myapp
The red and blue logs are flashing. They look normal. But the end was brutal:
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 see that the image exists.
Looking back at the harbor private server, the image also exists, but the error is speechless.
Go back to find more documents and come back to supplement.
Bold prediction: docker app will be an alternative to docker compose, just like swarm is to docker swarm, with the word as proof.