For some, Docker is second nature. The commands used are ingrained in their psyche. For others, however, it can be a chore to have to remember all those command line options. Is it docker image
, docker images
, or docker import
? Given how complicated container deployment and management can be, the last thing you want is to have to remember every single command option available.
SEE: Hiring kit: Back-end Developer (TechRepublic Premium)
Fortunately, if you’re working with Linux, there’s a hand tool that makes using the command line considerably easier: autocompletion. Just type the start of a command name and hit Enter. For example, if I type do and hit Enter, I might see the following:
do               dockerd-rootless-setuptool.sh
docker              dockerd-rootless.sh
docker-buildx          docker-init
docker-compose          docker-proxy
docker-credential-ecr-login   domainname
docker-credential-none      done
docker-credential-pass      do-release-upgrade
docker-credential-secretservice dosfsck
dockerd             dosfslabel
That’s great, but most likely you already know the command you need is docker
. What you might not know is which commands to use with docker.
Out of the box, completion isn’t enabled for Docker. Thankfully, it’s actually pretty easy to add. Once you do add it, you’ll find it considerably easier to work with the Docker CLI.
Let me show you how to add completion to the docker command on Linux.
What you’ll need to add completion for the docker command
To make this work, you’ll need a Linux distribution with Docker installed and running, as well as a user with sudo privileges. That’s it.
How to add completion to the Docker CLI
The first thing you must do is install the completion tool, which can be done with one of the following commands:
On RHEL-based systems – sudo dnf install bash-completion -y
On Debian-based systems – sudo apt-get install bash-completion -y
Next, we need to download the Docker complete file and save it into the proper directory with the command:
sudo curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
If you get a permission error, you might have to first issue the command:
sudo -s
Once you’ve done that, attempt the curl command again and it should work just fine.
You’ll then need to log out and log back into your Linux system. After that, you can test the auto-completion by typing something like:
docker p
Hit Tab twice and you should see something like this in the output:
pause  plugin port  ps   pull  push
One little trick is if there is only one match — such as with b, as in build — you only need to hit Tab once. If you type a letter after the docker command and nothing happens, hit Tab again to view all of the matching entries.
And that, my friends, is how you can dramatically simplify the Docker CLI, so you don’t have to remember every command option available. It may not help you build and deploy containers, but it’ll certainly keep you from having to memorize every option available to the command.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.