Contact Corfitz

Docker saved me!

Well a bit extreme, but I recently had to create a simple network of microservices which required for me to create a local testing environment and still have the ability to live code on them. I am used to write some services in Node.js using Nodemon for automatic updates on changes, but in this instance, one microservice had to be built in PHP, and usually I would have MAMP running with multiple host-aliases, but in this case the local management became a huge headache.

In came Docker as the obvious solution to this – and no… This is not me advertising for Docker, though it deserves a lot of attention – no actually, Using Docker and running it as a separate network was ideal to build this, and let me share a few new things I came to realise building it this way.

  • When using a local MongoDB on your local machine, it won’t become part of the network created. Therefor you have to specify your Mongo address to be http://host.docker.internal:27017.
  • If each microservice has a dedicated docker-compose.yml file, you have to create the network manually in the terminal [>$ docker network create [OPTIONS] NETWORK] and hereafter add this network in the bottom of your compose-file:

    networks:
        default:
            external:
                name: NETWORK
  • Use Nodemon as a devDependency in your node servers, but remember to add a script for production which alters the NODE_ENV variable to “production”. Inside your Dockerfile you should make sure to add the NODE_ENV as development by default but changeable according to ARGS set by the docker run command.

Awesome right!?


Posted: 2019-04-30


Read more gakker