The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Deploy Node.js on Docker

Deploy Node.js on Docker

9:54
Getting nodejs to run inside of Docker is relatively simple. Getting nodejs to run inside of Docker while using recommended best practices takes some planning. In this lesson, I’ll show you how to get a simple nodejs web server running in Docker on your local workstation while adhering to best practices.
Watch this lesson now
Avatar
egghead.io

Getting nodejs to run inside of Docker is relatively simple. Getting nodejs to run inside of Docker while using recommended best practices takes some planning. In this lesson, I’ll show you how to get a simple nodejs web server running in Docker on your local workstation while adhering to best practices.

Avatar
Adam

I'm still a little confused as to why you needed to create a new volume for /home/nodejs/app/node_modules. You've already mounted the entire project directory which contains the node_modules you have installed locally. Why can't the container just use those? Also, You didn't specify a "matching" directory when you mounted the 2nd volume. What is this doing? From what I understand this is creating a directory locally that only the Docker engine has access to (well, for the most part).

Avatar
Will

You are correct.
The node_modules folder on my local workstation has modules compiled for OSX, but my docker host is running Linux. The new volume was needed to provide a location for the docker host to place the npm modules compiled for its OS (Linux in this case).
The 2nd volume is created locally on the docker host. Since it contains the npm modules compiled specifically for its OS, they aren't of any use outside of the docker host so I didn't expose it.

In reply to Adam
Avatar
Alexandre

Hi Will,

I needed to add : RUN mkdir $HOME/app after ENV NODE_ENV=production
in my Dockerfile, don't know if it's related to Docker version or something else but without I had a missing dir error when docker was running npm install on build

Best !

In reply to Will
Avatar
Will

Nice catch!
It may be that, or an oversight by the author when recording the lesson! :-D

In reply to Alexandre
Avatar
Alexandre

EDIT: Service 'app' failed to build: When using COPY with more than one source file, the destination must be a directory and end with a /

Need to replace:
COPY package.json npm-shrinkwrap.json $HOME/app
by
COPY package.json npm-shrinkwrap.json $HOME/app/

Avatar
Will

Yup, that was a typo on the screen during recording. The git repo with the lesson has the corrected trailing slash on the command. I'll update the lesson to correctly show that as well.
Thanks!

In reply to Alexandre
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?