Turn any script into a Docker Extension in about 3 minutes*

Tom Shaw
DevOps Dudes
Published in
3 min readMay 25, 2022

Docker Extensions were announced at DockerCon 2022 and are currently in beta. More details can be found here.

Docker Extensions are available as part of Docker Desktop 4.8.0 or a later release.

What are Docker Extensions ?

Docker Extensions are Docker images stored in DockerHub (or any image registry) which enable you to integrate your own tooling directly into Docker Desktop. These images are built and pushed in the same way as any regular image. As a tool builder and someone who works with developers on a day-to-day basis this holds huge potential. Many of us have scripts and containerised tools shared across our organisations. These may be called from a makefile, a shell alias or some type of wrapper. While this works to a certain degree it can often be challenging for developers to keep their local tooling up-to-date and many of the problems I deal with daily are due to versioning and dependency drift on the developers local machine.

This is where Docker Extensions hold so much potential. Imagine tweaking your existing containerised tools and scripts, pushing them to a Docker Registry and developers being able to “one-click” upgrade the tool on MacOS, Windows and Linux. This sounds over simplified but that’s exactly how it works and this example code can be used as scaffolding to take an existing script and turn it into an extension in minutes.

How does this work?

WARNING! Shells started by this plugin use an unsecured connection, have no password protection, and provide root access to your machine. Use at your own risk!

The majority of this work was done by Sebastiaan : https://twitter.com/thaJeztah and I just tweaked it to make it work for my use case.

The steps below will walk through the steps to build an extension from source and install it. The beauty of extensions is that they are docker images so you can run : docker extension install <image>:<tag> and you have the extension installed and ready to use.

Let’s get started.

git clone https://github.com/tomwillfixit/docker-extension.git

Follow the instructions in the README to install the Docker Extension CLI plugin and run each step sequentially.

When the extension is installed it will show up in the Docker Desktop UI :

So how does this work?

The code uses GoTTY, nsenter and this line in the Dockerfile to execute your script automatically:

RUN echo “cd / ; ./menu.sh” > /root/.profile

GoTTY shares the extension container as a web application and the ui/index.html file uses an iframe to display the application. nsenter enables you to enter the extension container namespace, and the .profile line ensures your script is the first command that nsenter runs.

The above is a quick and easy way to get started with Docker Extensions and a great way to get to grips with how extensions are built.

If you found this blog useful or simply have a kind heart → https://ko-fi.com/tomwillfixit

--

--