One thing I really dislike when trying to install new command line (CLI) software is the uninstall process isn’t always very clear. Things can get worse if the software has additional dependencies (Java for example) especially when you need to have two versions of the same tool for different apps.
Docker solves this problem by keeping everything you need for a specific task in one container. The added bonus is that you’ll probably be able to find a Docker container for just about anything you want and it’s OS independent on Docker Hub.
Most of the demos I’ve seen for containers that are used for CLI tools looked like this:
Though these containers are helpful it’s not really useful for end users (i.e. developers) since the command can be tough to remember and the containers may exist after running the tool (i.e. you may need to manually delete them.
When building the Amazon ASK CLI container I wanted to avoid these issues to make it as easy as possible for developers to use. I did the following tricks:
Instead of having to remember the long
docker run command with all the parameters I used an
alias command to bundle it all together. Mine looked like this:
A few key things to note from the above snippet:
alias: This means that anytime I type in
alexain bash it will run everything in the quotes.
- Windows users:
aliasdoesn’t exist in DOS or PowerShell. I’m not aware of any alternatives. If you know of any easy ones please leave a comment and I’ll update this post
- Windows users:
--rmoption: Deletes (self destruct) the container after the command is run. This means is that when I run
alexa ask init(where
ask initis the CLI tool) it’ll
runthe container, execute
init), then remove the container once
--rm techniques you can easily have all the CLI tools you want without cluttering up your base machine. Of course there may be some minor performance impacts by Dockerizing them. Personally I didn’t notice any slowdowns and will start using this technique for all my future CLI tools.