Skip to content

Commit 36e65c4

Browse files
authored
Merge pull request #61 from rumpl/document-init
Add documentation about the init command
2 parents 0995801 + 622dfb5 commit 36e65c4

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

docs/dev/cli/usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The Extensions CLI is an extension development tool that can be used to manage D
44

55
- `docker extension enable` - enable Docker extensions
66
- `docker extension disable` - disable Docker extensions
7+
- `docker extension init` - create a new Docker extension
78
- `docker extension install ` - install a Docker Extension with the specified image
89
- `docker extension ls` - list installed Docker extensions
910
- `docker extension rm` - remove a Docker extension
Loading

docs/tutorials/initialize.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
In this tutorial you will learn how to create a new Docker Desktop extension
2+
3+
## Prerequisites
4+
5+
- [Docker Desktop build with Extensions capabilities](https://github.com/docker/desktop-extension-samples/releases/)
6+
- [Docker Extensions CLI](https://github.com/docker/desktop-extension-samples/releases/)
7+
- [node](https://nodejs.org)
8+
9+
## Creating a new extension
10+
11+
To create a new extension run
12+
13+
```bash
14+
docker extension init my-extension
15+
```
16+
17+
and answer the questions.
18+
19+
This will create a directory `my-extension` with a bare-bones extension code.
20+
21+
This extension contains:
22+
23+
- A backend that listens on a socket, it has one endpoint `/hello` that returns
24+
a JSON payload
25+
- A React frontend that can call the backend and output the backend response
26+
27+
## Build the extension
28+
29+
```bash
30+
cd my-extension
31+
make extension
32+
```
33+
34+
## Install the extension
35+
36+
Now that the extension is packaged as a Docker image, let's proceed with the
37+
installation. To do so, we'll use the Docker Extensions CLI.
38+
39+
!!! info "Enable Docker Desktop Extensions"
40+
41+
Ensure the Extensions capabilities are enabled in the Docker Desktop build
42+
by running `docker extension enable`
43+
44+
To install the extension in Docker Desktop, run:
45+
46+
```bash
47+
docker extension install my-extension
48+
```
49+
50+
If the installation was successful, you should see the following output:
51+
52+
```bash
53+
Installing new extension "my-extension"
54+
Installing service in Desktop VM...
55+
Setting additional compose attributes
56+
VM service started
57+
Installing Desktop extension UI for tab "My-Extension"...
58+
Extension UI tab "My-Extension" added.
59+
Extension "my-extension" installed successfully
60+
```
61+
62+
## Preview the extension
63+
64+
You can verify that the extension has been installed successfully using the
65+
following CLI command:
66+
67+
```bash
68+
docker extension ls
69+
```
70+
71+
It outputs all the extensions installed:
72+
73+
```bash
74+
ID PROVIDER VERSION UI VM HOST
75+
my-extension Docker Inc. 1 tab(My-Extension) Running(1) -
76+
```
77+
78+
On the left-menu, you should see a new tab with the name `My-Extension`. Click
79+
on it to load the main window that will render a button. When you click on it
80+
you should see the response from the backend
81+
82+
![UI Extension](images/initialized-extension.png)
83+
84+
### Opening Dev Tools
85+
86+
To open the Chrome Developer Tools, see [this](../../dev/overview).
87+
88+
### Iterate faster while developing
89+
90+
To iterate faster and try out new changes when developing the extension, use the `docker extension update` command to uninstall the previous version and install the new one with your latest changes.
91+
92+
### Developing the frontend
93+
94+
If you are working on the frontend code of your extension and don't want to
95+
rebuild the extension image each time you can setup Docker Desktop in a way
96+
that will use your development server instead of the bundled frontend code from
97+
the extension image. To do that, in one terminal start your UI development
98+
server:
99+
100+
```bash
101+
cd ui
102+
npm start
103+
```
104+
105+
This will start a development server that listens on port 3000. You can now tell
106+
Docker Desktop to use this as the frontend source, in another terminal run:
107+
108+
```bash
109+
docker extension dev ui-source my-extension http://localhost:3000
110+
```
111+
112+
Close and reoped the Docker Desktop dashboard and go to your extension, all the
113+
changes to the frontend code will now be immediately visible.
114+
115+
Once you are done you can remove the ui-source override by running
116+
117+
```bash
118+
docker extension dev reset my-extension
119+
```
120+
121+
122+
## Clean up
123+
124+
To remove the extension run:
125+
126+
```bash
127+
docker extension rm my-extension
128+
```
129+
130+
The following output should be displayed:
131+
132+
```bash
133+
Removing extension my-extension...
134+
Removing extension VM service...
135+
Extension removed from Desktop VM
136+
VM service socket forwarding stopped
137+
Extension UI tab My-Extension removed
138+
Extension "my-extension" removed
139+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ markdown_extensions:
3939
nav:
4040
- Introduction: index.md
4141
- Tutorials:
42+
- Create your first extension: tutorials/initialize.md
4243
- Create a minimal frontend extension: tutorials/minimal-frontend-extension.md
4344
- Create a minimal backend extension: tutorials/minimal-backend-extension.md
4445
- Create a ReactJS-based extension: tutorials/react-extension.md

0 commit comments

Comments
 (0)