Handy Docker Aliases – Hacker Noon

Now on to our aliases… this better be good right?

The first aliases we’ll look at simply provide abbreviations for common docker commands.

Right off the bat, consider the time saving every time you replace docker with dk for commands like docker ps or when working with services and using dks for docker service commands like docker service ls. The savings of typing dks ls add up!

So instead of typing docker: docker logs you type: dkl

docker logs b7a8 becomes dkl b7a8

Use dklfto follow a log. So rather than docker logs -f b7a8 you can simply use dklf b7a8

Another handy logging alias is the dkln (docker log by name) command.

It evaluates the piped commands within the backticks (`) and utilizes the result as a parameter to the docker logs command. The grep command uses the first parameter to filter the results of the docker ps command. And finally, the awk command takes the first field of the output as the value parameter.

Ok, that might be confusing. Let’s take a closer look.

The docker ps command returns a list of running containers.

Abbreviated docker ps output

And docker ps | grep redis returns:

Abbreviated output

And finally, docker ps | grep redis | awk '{print $1}' return the container ID for Redis: f5f0ed387073

This allows us to view the log for any container by name.

Abbreviated docker ps output

Naturally, you’ll need to make sure you don’t have multiple containers which match a name. If you do, then simply resort to the dkl command with a container ID.

A key takeaway in the example above is that you can build some pretty powerful aliases by combining shell commands. We’ll see another example of this later in this post, when we look at an alias for building and publishing containers.

read original article here