[Intro Music]
All right, we have just pulled 'node'
image from Docker Hub; and we
have created first a Node.js
container, and we have basically
executed some commands like console.
log, or assignment of the value to
the variable inside of the
interactive interpreter of Node.js
inside of the container. And now
let's create the sample Node.js
application as we did with Python,
and let's do that on our local
computer, and afterwards, let's run
it using Node.js container. Let me
clear terminal and go to Visual
Studio Code, and create here,
new folder near folders 'nginx',
'python', and so on. Let's close any
related to previous projects files.
And here let's create a new folder,
and let's name it 'node', like so.
And here inside of this folder,
let's create a new file, simply
hello.js, like this. And here in
this file, let's simply type
console.log('This application
was executed by Node.js container')',
like so. Let's save this. And also
you're able to wrap long lines
using key combination 'Alt' + option
'z', like so. And let me hide this
left pane and we are actually ready
to go and we are ready to execute
this tiny application inside of the
single file hello.js using Node
container. Let's go to terminal and
of course, you may guess that we
need to use here volume mapping
in order to map our volume on our
local computer to a specific folder
inside of the container that will
be running Node.js. Let's do so.
Let's first 'cd' to 'node' folder,
because we will use the same as
before, variable 'PWD'; and that's why
we need to be inside of the folder
that has files that we need to map
to container. Let's 'cd' to 'node', and
here let's run container, 'docker
run -v', we will use a volume mapping,
'$PWD', next ':', and let's map
this local folder to '/app' folder,
same as we did in Python
application. And of course, let's
specify here working directory
inside of the node container using
'-w' option, and here
let's type '/app', like so. And
next comes 'node', it is name of the
image that we will use for creation
of this container. And afterwards,
let's override the default command,
that is actually 'node' command,
using 'node', plus name of the file
that we want to execute inside of
the container. And for that, let's
simply type 'node'', and next comes
name of the file, and name of our
file is 'hello.js'. Let's here
type 'hello.js'. And please note
that here is command that will be
executed upon creation of the
container. Here's name of the
image. Great. Let's press Enter, and
see what will happen. And I see
result, 'This application was
executed by Node.js container'; and
that means that our script, hello.js
was successfully executed by
Node.js container. But after
execution of the script, process,
'node' process was terminated; and
container was stopped. We could
verify that as usually using 'docker
ps' command. There are no containers
at the moment. This is how you're
able to run a very simple
application using Node.js
container. And notice that we were
not required to create port mapping
because this application doesn't
require any external ports. But if
you create any for example API
using Node.js, then you probably need
to open some ports in order to
access endpoints, API endpoints from
external clients. Great. This is how
we are able to run very simple
application using Node.js But please
note that things may become more
complicated if you want to install
some additional dependencies using
npm. Let's try to create a bit more
complicated Node.js application that
will require some additional NPM
modules. Let's do that next. Bye-Bye.
[no audio]