Filter Out Docker Noise

Sometimes the smallest lil’ gem makes you feel great. For me, Docker’s --format option is one such gem. As much as I love Docker, for me, their commands’ output are far too verbose and noisy. In fact, the net is filled with complaints about this. However, the --format option makes them perfect… or closer to perfect. Even the noisiest command can be transformed…

… from this …

Before Docker Aliases

… to this …

After Docker Aliases

… in just a few extra keystrokes!

It outputs just the right amount of info to be particularly great for “4-up” or “2-up” arrangements…

Docker Aliases with 4 Up Display

Docker’s info for the ps command completely sucks and offers no info on this option. In short, you basically use it to tell Docker what columns to display. For example, with ps you have the following columns to choose from:

  • ID
  • Image
  • Command
  • RunningFor
  • Status
  • Ports
  • Names

So, for the example above, the syntax would be:

docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Ports}}"  

Or, better yet, if you’re on Linux or macOS / OSX, take a few seconds and create aliases for dps and dpsa in your ~/.bash_aliases file by adding these two lines:

alias dps='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Ports}}"'  
alias dpsa='docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Ports}}"'  

Enjoy… finally! =)

(I’ve added these two aliases to my dotfiles project, if you’re following that project.)

Pattern for Developing Complex Solution with NodeJS within Docker

So many of the examples out there, for both Node and Docker, show simple little applications. They might demonstrate how to create a container. Another might show how to crank up your first NodeJS app. However, I have yet to find one that demonstrates how to use these bag o’ widgets in a real world application.

Hopefully, my mean-docker example, on Github, will help show how to bring it all together. Something within me wants to create a small how-to video series surrounding it, however, there are several good folks out there already tackling the meat of this (check out Derick Bailey’s WatchMeCode for back-end goodness). So, who knows? In the meantime, here’s what this project will give you:

(BTW: Here’s the direct link on GitHub, in case you missed it: mean-docker)

Project Breakdown

mycompany-api0x

Three back-end microservices (for some reason the Node world is referring to them as “APIs”… which annoys the heck out of me) stubbed-out in NodeJS and Express.

mycompany-app

The front-end Angular app which calls into the example APIs.

mycompany-www

Your example company’s web site. Again, this is just stubbed out.

solution-a & solution-b

Two higher-level solutions containing all of the “good stuff” for Docker & NGINX.

Getting Started

There’s not much to it. Here’s what to do:

  1. Install Git & Docker on your development machine.
  2. Clone the Git repo to your machine:git clone https://github.com/FredLackey/mean-docker.git
  3. Navigate into either solution-a or solution-b (currently identical):cd ~/Source/Github/FredLackey/mean-docker/solution-a
  4. Spin up Docker and let’er do it’s magic:docker-compose up
  5. NGINX is listening to a few URLs specifically, so you may want to edit your /etc/hosts or %SYSTEM32%\drivers\etc\hosts file and add the following entries (a copy is in the provided %SOLUTION%/.docker/etc/hosts file):
127.0.0.1       mycompany.com www.mycompany.com
127.0.0.1       app.mycompany.com
127.0.0.1       api01.mycompany.com
127.0.0.1       api02.mycompany.com
127.0.0.1       api03.mycompany.com

Working With It

Automated “watchers” are already setup to handle all of the compiling, optimising, starting, and restarting for you. Simply do your work in the typical %PROJECT%/src/server and/or %PROJECT%/src/client folders and everything else will be taken care of for you.

On a completely clean dev machine, it should take approximately three minutes for an initial build:

Example Running Blocks

If you updated your /etc/hosts or %SYSTEM32%\drivers\etc\hosts file with the names of the servers, you may check the status of each project using any web browser:

Example Project Site

… or …

Example API Test

Limitations

The goal of this project is to get you started and help demonstrate some of the concepts… getting NGINX to talk to proxy your requests, linking docker containers, automagically detecting changes, etc. That being said, it works for this purpose but it’s not an actual working solution. If you have a need for such a thing, let me know and maybe I can spend some additional time on it.

Enjoy! =)