Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker development workflow with node.js

I'm trying to use docker with a node.js web app i'm working on.

I have familiarized myself with the docker concepts and gotten up and running with the example here: https://docs.docker.com/examples/nodejs_web_app/

I get the general process...write a Dockerfile -> Build a docker image -> run it in a VM.

However, it seems impractical to rebuild the image and restart the container every time I change a file.

I currently have a gulp / live-reload setup that works great for development so I was wondering if there was any recommended way of accomplishing something like this with docker.

Thanks!

like image 546
john_ryan Avatar asked Sep 05 '15 15:09

john_ryan


People also ask

How do I Dockerize node JS application?

Create the Node.js app 'use strict'; const express = require('express'); // Constants const PORT = 8080; const HOST = '0.0.0.0'; // App const app = express(); app.get('/', (req, res) => { res.send('Hello World'); }); app.listen(PORT, HOST, () => { console.log(`Running on http://${HOST}:${PORT}`); });

What is Node JS in Docker?

Node.js is a JavaScript-based platform for server-side and networking applications. docker pull node. OverviewTags.

How do I setup a docker development environment?

Launch from a local folder From Dev Environments in Docker Dashboard, select Create. The Create a Dev Environment dialog displays. Select Get Started and then choose Local Folder as the source. Next to Select your local directory field, select Select to open the root of the code that you would like to work on.

Does Docker use node?

Docker Engine 1.12 introduces swarm mode that enables you to create a cluster of one or more Docker Engines called a swarm. A swarm consists of one or more nodes: physical or virtual machines running Docker Engine 1.12 or later in swarm mode. There are two types of nodes: managers and workers.


1 Answers

You can mount the source directory in the container as a volume and use the same gulp/livereload setup that you currently use now. Here's an example project with this setup. If you run into port issues with livereload see here.

like image 59
Kevan Ahlquist Avatar answered Sep 29 '22 04:09

Kevan Ahlquist