Running node.js in Docker during development
Docker for development
After coming across being convinced by this article that Docker is a useful tool for running a dev environemnt, I’ve been running my recent Node.js-based FitBit logger project from a Docker container. I’m looking at Amazon’s EC2 Container Service to host the thing, so I’m writing basic Docker rather than something fancier like Compose.
Setting up a Node.js container
This tutorial on the docs.docker.com site goes through the process of building a Docker image for Node.js. Here is the one I ended up with by following their instructions:
Note the install -g nodemon
: Nodemon will monitor your filesystem for changes and restart a Node.js server when source code is modified.
This is how I start up my container using Nodemon:
One thing to watch is that you have to have run npm install
at least once locally, so that the node_modules
directory is created. You need this because the contents of the local source directory will get copied over the container source directory with the -v /Users/miller/dev/fitbit-logger:/src
portion of the command.
Now you can edit your code and have it reflected in your Docker container automatically, without having to run additional commands on the container!
Comments