Useful aliases for Docker on OSX

After downloading and installing docker toolbox, many docker tools will be present on your OSX : docker engine, docker-machine, docker-compose. These are aliases that I am using to work with the docker tools on OSX.

How to use these aliases?

Copy the aliases in your file ~/.profile and in a terminal execute the following command:

Very short aliases

Docker toolbox installs many executables beginning by docker, so the combo “do” + TAB in the terminal is not efficient anymore. I use very short aliases, not amazing but useful 🙂

Start a docker machine

Every time you boot your iMac or your MacBook, you must start a docker machine, i.e. a virtual machine hosting the docker engine, by running the command:

I create a docker-machine-start function and I bind it to an alias. So executing:

will launch the default docker machine, create the environment variables for this host and create an extra environment variable DM_HOST which contains the IP address of the launched machine. This environment variable can be useful for referring to this IP address in your docker compose files, or to connect to the host via SSH for example.

Clean containers and images

When you build your own docker images, a lot of unused images can populate your local docker, this following alias removes these images:

And finally, this last alias removes all the created containers:

If you are using some aliases for docker too, you can share them with us!

Leave a Reply

Your email address will not be published. Required fields are marked *