New Docker Image – 20i Domain Checker3 min read

I’m a stickler when it comes to repetitive tasks, especially so when it comes to work and tech related things – if I have to do something more than three times, I’ll often find a way to automate it, or make it easier in some way.

One task that’s been bugging me for a little while is checking the availability of domain names for friends, family and clients.

I have to load the 20i website, log in, click the domain order page, enter the domain name, click the search button, wait for the response, then look to see what it says – thats way too much like hard work for my liking… especially when I do it quite frequently.

So – I spent a few hours this morning creating a command line domain availability checker that can be run from a container (my favourite way of running things.

I can now perform:

domaincheck mynewdomainname.com
domaincheck mynewdomainname.com myotherwanteddomain.co.uk

or

domaincheck mynewdomainname.com,myotherwanteddomain.co.uk

and I almost instantly get a response back on if that domain is available, and if so – a link to click* to go and continue with the order.

*I use iTerm2 which parses URL’S and offers a CTRL+Click to follow

The Concept

20i offer an extensive API that interfaces with pretty much everything on their hosting platform; one of which – is a domain name availability endpoint.

You have to a full reseller to gain access to the API, and access to it gains you full access, so security was at the forefront of the image.

I wanted to create an image that I could make public, and work work for everyone – obviously without revealing my API key – users would need to use their own. This lead me to utilising API key sharing through environment variables that the container would then use to interface with the API.

This has enabled the image to be published on the Docker Hub: https://hub.docker.com/r/danstreeter/20i-domain-check/ and the underlying code on GitHub https://github.com/danstreeter/20i-domain-check.

Under the hood

The image itself is a simple one, based on a base PHP 7.2 CLI Alpine container and running a very simple script to determine the passed in arguments, parsing them by position for the API key and domain names and throwing that into the GET request to 20i.

I wanted the image to be light, its assets to be self contained and just run, so used Dockerfile multi-stage builds to first collect the required composer assets, loading them into the main PHP container via the COPY –from instruction.

The parsing of parameters is handled by the single PHP script, and expects the API key to be passed in as the first parameter, then any domain names after that, either separated by space, or comma, that makes a plain run of the container like this:

docker run --rm danstreeter/20i-domain-check $TWENTYIAPIKEY domainone.com domaintwo.co.uk

From there, the script just works out what type of domain list you’ve sent, building an array, looping over each one performing the API request and offering the result back.

Easy peasy!

More info

I’ve submitted a README within the repo with instructions and usage: https://github.com/danstreeter/20i-domain-check/blob/master/README.md which has how you can get the same results as me above, using alias’s to shorten the command further.

All in all, took me a couple of hours give or take, messing around and sorting the boys out with breakfast etc – a couple of hours well spent if you ask me!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.