Docker Build Hanging?

TLDR; create a .dockerignore file to filter out directories which won’t form part of the built image.

Long version: working on the upcoming Kubernetes course, with a massive deadline looming over me [available at VirtualPairProgrammers by the end of May, Udemy soon afterwards], the last thing I need is a simple docker image build freezing up, apparently indefinitely!

A quick inspection of running processes with Procmon (I’m developing on Windows) showed a massive number of files being read and closed:

This just a small extract from the process log.

This [every file in the repository being visited] is normal behaviour of the docker image build process – I guess I’ve just been working on repositories with a relatively small number of files (Java projects). This being an Angular project, one of the folders is “/node_modules” which contains a masshoohive number of package modules – most of which aren’t actually used by the project but are there as local copies. This directory can be easily regenerated and isn’t considered part of the project’s actual source code. [edit to add, it’s the equivalent of a maven repository in Javaland. The .m2 directory is stored outside your project, so this isn’t a concern there].

Turns out, the /node-modules folder contained 33,335 files whilst the rest of the project contained just 64 files!

Routinely, we .gitingore the /node_modules folder, and of course it makes sense to ignore this directory for the purposes of Docker also.

Simply create a folder in the root of the project, .dockerignore:

$ cat .dockerignore
/node_modules

You might also consider adding .git to this ignore list.

Now my docker image build is taking a few seconds instead of several hours. Perhaps I might meet this deadline after all…

Problems with dockerHost in Maven?

A problem reported against my Docker Module 2 course:

This happens on Windows Toolbox (ie anything below Windows 10 Pro) and possibly Mac toolbox as well.

If your Maven build is failing (with the fabric8 plugin) you need to add additional configuration. On the Docker Toolbox command line type

docker-machine env

Observe the output: you’re looking for the entries for DOCKER_HOST and DOCKER_CERT_PATH. Add the values you find here into your Maven pom, something like this:

<configuration>
<dockerHost>tcp://192.168.99.100:2376</dockerHost> 
 <certPath>C:\Users\Richard\.docker\machine\machines\default</certPath>
...images tag etc here
</configuration>

Of course don’t just copy and paste these values – check they match the output of docker-env.

AllThingsJava Podcast

I’m back on the AllThingsJava podcast again. I had a shocking hangover when recording it so forgive my vague rambling.

Covered on this episode:

  • News – Javascript App gets sued for trademark breach – could it happen to us?
  • News – Java 10 features
  • News – (actually old news but since the last podcast) JavaEE is dead, long live JakartaEE.
  • Matt is planning a new course on Kotlin, coming soon.
  • I’m planning a new course on Kubernetes, coming even sooner. I’ll blog about this new course shortly. I should have done Kubernetes a year ago, I feel somewhat left behind and there are other good courses out there – I’m not sure how I can be different so I’m working on an “angle” right now. Hope I come up with something worth having.
  • There was some talk about whether we should do more on Javascript front ends. I think we should and I’m working on shoring up my skills in this area.