A few docker tips and tricks
Docker is an awesome technology that has gained quite a bit of steam of the last couple of years. With it’s high adoption among fancy start-ups to to enterprise level applications and development teams looking to tighten the feedback loop on the Software Development Lifecycle from Development, to testing and production environments. Below are a couple of tips and tricks I have uncovered since adopting Docker.
When developing an application that spans multiple microservices, as my reference application Med-Park does, it is quite common that one services will be dependent on one another. When setting up your compose file one option available to us would be the depends_on flag we could set for services and reference the service that a particular service is dependent on. Unfortunately, this flag only goes as far as ensuring the service was started, and not validating if it is fully available. To work around this, we could a command to ensure the service is completely up and running. For tis we could use the script linked below:
See this helpful step-by-step guide for assistance.
Once again, when having multiple service that need to run in Docker, use Docker compose. Docker compose let’s you set up a list of services and with additional config. Not only that, it is considered standard practice to have you Dockerfile’s in your project directories and building each can be tedious. Luckily, docker compose also supports the build command so you can go ahead and build all your docker images with one command.
See the link below to get started with compose:
I’m going to go out on a limb and assume you know what a .gitignore file is. Well, .dockerignore uses the same concept. Essentially, within you docker context there might be a couple of files that you just do not care about when building your images and you want to ignore them. This can be a huge benefit especially if your project has various dependencies and they are scattered all over.
When building your images temporary containers and images are created during this process but Docker does not do housekeeping very well. s a result, you are left with a bunch of dangling docker containers and images that could be taking up a lot of space on your machine.
Use the following command to clean up all stopped containers and images respectively:
$ docker container prune –f (-f to force cleanup and skip confirmation)
$ docker image prune –f
Check back later...
I will update this list as I continue honing my Docker skills going forward.
I hope at least one of these are of value to you going forward.