Skip to content

Docker Desktop Extensions

Docker Desktop Extensions 允许你为 Docker Desktop 开发自定义扩展。

什么是 Extensions?

Extensions 是 Docker Desktop 的插件,可以:

  • 扩展 Docker Desktop 功能
  • 集成第三方工具
  • 提供自定义 UI

开发 Extension

项目结构

my-extension/
├── metadata/
│   └── metadata.json
├── ui/
│   └── index.html
└── backend/
    └── main.go

metadata.json

json
{
  "name": "my-extension",
  "version": "1.0.0",
  "description": "My Docker Desktop Extension",
  "ui": {
    "entrypoint": "ui/index.html"
  },
  "backend": {
    "entrypoint": "backend/main"
  }
}

UI 开发

使用 HTML/CSS/JavaScript 开发 UI:

html
<!-- ui/index.html -->
<!DOCTYPE html>
<html>
<head>
    <title>My Extension</title>
</head>
<body>
    <h1>My Extension</h1>
    <script src="app.js"></script>
</body>
</html>

后端开发

使用 Go 开发后端服务:

go
package main

import (
    "net/http"
)

func main() {
    http.HandleFunc("/api/hello", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Hello from extension"))
    })
    http.ListenAndServe(":8080", nil)
}

安装 Extension

sh
# 从本地目录安装
docker extension install ./my-extension

# 从远程安装
docker extension install my-extension:latest

发布 Extension

构建 Extension

sh
# 构建 Extension 镜像
docker build -t my-extension:latest .

发布到 Docker Hub

sh
docker push my-extension:latest

参考资源


由 BSFC Tech 提供技术支持