Creating Your Own Docker Extension in Docker Desktop

Photo by Ian Taylor on Unsplash

Creating Your Own Docker Extension in Docker Desktop

ยท

3 min read

Play this article

What are Docker extensions?

Docker extensions are a great way to integrate your application to the docker desktop to avoid the command line and make the developer's life easier by providing services with a click of a button.

Nice And Easy

image.png

How to create my own Docker extension?

Yeah yeah, I hear you. Now let's do this ๐Ÿ’ช

  • Installing the Docker-extension CLI:

Since the Docker Extension feature was recently added, it is not built into Docker CLI. So we must download the executable file. You can download it from here

  • Extract the tar file by running (Make sure you are in the downloads folder)
  tar -xf desktop-extension-CLI-windows-amd64.tar.gz
  • Move the docker-extension.exe to ~/.docker/cli-plugins
 mkdir -p ~/.docker/cli-plugins
 mv docker-extension.exe ~/.docker/cli-plugins
  • List all your extensions by running the following command:
  docker extension ls

Here's the result:

 ID                                     PROVIDER            VERSION             UI                          VM                  HOST 
 docker/disk-usage-extension            Docker Inc.         0.2.4               1 tab(Disk usage)           -                   -
 docker/minimal-docker-cli-extension    Docker Inc.         latest              1 tab(Minimal Docker CLI)   -                   -
portainer/portainer-docker-extension   Portainer.io        2.13.1              1 tab(Portainer)            Running(1)

Building and installing the sample extension

Docker provides a ready-to-go example that represents a UI Extension invoking Docker commands. You can clone it from here

git clone https://github.com/docker/extensions-sdk/
cd /samples/minimal-docker-cli
  • Building the extension

    If you have make installed, then you can run make build-extension or go to makefile and copy the command docker build --tag=docker/minimal-docker-cli-extension:latest and run it.

    make build-extension
    docker build --tag=docker/minimal-docker-cli-extension:latest .
    [+] Building 2.7s (15/15) FINISHED
    => [internal] load build definition from Dockerfile                                                                                           0.0s
    => => transferring dockerfile: 1.72kB                                                                                                         0.0s
    => [internal] load .dockerignore                                                                                                              0.0s
    => => transferring context: 2B                                                                                                                0.0s
    => [internal] load metadata for docker.io/library/node:17.7-alpine3.14                                                                        2.6s
    => [client-builder 1/8] FROM docker.io/library/node:17.7-alpine3.14@sha256:539e64749f7dc6c578d744d879fd0ec37f3afe552ae4aca9744cc85121728c4c   0.0s
    => [internal] load build context                                                                                                              0.0s
    => => transferring context: 416.06kB                                                                                                          0.0s
    => CACHED [client-builder 2/8] WORKDIR /app/client                                                                                            0.0s
    => CACHED [client-builder 3/8] COPY client/package.json /app/client/package.json                                                              0.0s
    => CACHED [client-builder 4/8] COPY client/yarn.lock /app/client/yarn.lock                                                                    0.0s
    => CACHED [client-builder 5/8] RUN yarn config set cache-folder /usr/local/share/.cache/yarn-arm64                                            0.0s
    => CACHED [client-builder 6/8] RUN --mount=type=cache,target=/usr/local/share/.cache/yarn-arm64 yarn                                          0.0s
    => CACHED [client-builder 7/8] COPY client /app/client                                                                                        0.0s
    => CACHED [client-builder 8/8] RUN --mount=type=cache,target=/usr/local/share/.cache/yarn-arm64 yarn build                                    0.0s
    => CACHED [stage-1 1/2] COPY --from=client-builder /app/client/dist ui                                                                        0.0s
    => CACHED [stage-1 2/2] COPY metadata.json .                                                                                                  0.0s
    => exporting to image                                                                                                                         0.0s
    => => exporting layers                                                                                                                        0.0s
    => => writing image sha256:1ca1b1b61e281756c61ee9c42e90f9c6e0231c988c2417799fb348b4e74559e3                                                   0.0s
    => => naming to docker.io/docker/minimal-docker-cli-extension:latest
    
  • Installing the extension on Docker Desktop

    Now that your image is built we should tell the Docker Desktop that the image is an extension

     docker extension install minimal-docker-cli-extension:latest
    

And you're done ๐Ÿ’ช

image.png

References

Did you find this article valuable?

Support Collabnix by becoming a sponsor. Any amount is appreciated!

ย