< Return to Video

Module 3, Video 7

  • 0:05 - 0:09
    The traditional 3 tier application starts
    with the browser,
  • 0:09 - 0:10
    which is the client.
  • 0:10 - 0:12
    It then has an HTTP server,
  • 0:13 - 0:15
    and then it has a database for storage.
  • 0:16 - 0:18
    Now depending on what you're working
    with,
  • 0:18 - 0:22
    it's going to take a long time to
    configure this development environment.
  • 0:22 - 0:26
    Now we're going to go ahead and do this
    with Docker in a couple of minutes here,
  • 0:26 - 0:28
    maybe more like five minutes,
  • 0:29 - 0:32
    and we will be leveraging images that have
    been predefined.
  • 0:32 - 0:35
    On the lefthand side you can see the base
    image
  • 0:35 - 0:38
    that simply gives you your operating
    system.
  • 0:38 - 0:42
    The middle one is Node, which will be our
    HTTP server.
  • 0:42 - 0:44
    Someone has gone through the trouble,
  • 0:44 - 0:47
    in this case, the official creators of
    Node,
  • 0:47 - 0:49
    of creating an official Node image.
  • 0:49 - 0:54
    The same thing can be had from the
    Mongo image.
  • 0:54 - 0:56
    Now I'm going to go ahead and show you
    where they come from,
  • 0:57 - 0:59
    and they come from Docker Hub.
  • 0:59 - 1:02
    And if we go into it and we search for
    Node,
  • 1:03 - 1:04
    I'm going to go ahead and enter that.
  • 1:05 - 1:08
    We can see here that there is an official
    Node image
  • 1:08 - 1:12
    with over 2,000 stars and
    over 10,000,000 pulls.
  • 1:12 - 1:18
    Now, if we do the same thing for Mongo,
    we see similar numbers.
  • 1:18 - 1:21
    So obviously these are widely used by the
    community
  • 1:21 - 1:27
    to be able to pull in larger Lego blocks
    to start building our application.
  • 1:28 - 1:31
    So I'm going to go ahead and move to
    the terminal now.
  • 1:33 - 1:38
    But right before I run my build of all
    my images,
  • 1:38 - 1:40
    let me go ahead and show you what's in
    the file.
  • 1:41 - 1:42
    I've created these.
  • 1:42 - 1:46
    As you can see here, I have a Dockerfile
    and a docker-compose.
  • 1:47 - 1:51
    The very first line references that Node
    image,
  • 1:51 - 1:52
    that official Node image.
  • 1:52 - 1:56
    It will look for it locally, if it doesn't
    have it, it'll pull it down
  • 1:56 - 2:00
    and use that to add the additional
    commands.
  • 2:00 - 2:03
    I then, within this fresh new image,
  • 2:03 - 2:05
    you can think of it as a new machine,
  • 2:05 - 2:08
    I'm going to add a working directory.
  • 2:08 - 2:10
    I then install nodemon
  • 2:10 - 2:15
    and I do this because I'm going to be
    configuring a Node server application,
  • 2:15 - 2:19
    and every time I make a change, I want it
    to stop and reload.
  • 2:20 - 2:23
    I then copy over a package.json
  • 2:23 - 2:28
    that simply has the requirements for
    this particular application.
  • 2:28 - 2:32
    I then run npm install so that it loads
    whatever packages
  • 2:33 - 2:35
    Node needs in this case for this
    application.
  • 2:35 - 2:37
    I then copy over.
  • 2:37 - 2:43
    My server is just simply server.js and I
    expose port 3000.
  • 2:44 - 2:49
    Now, my docker-compose brings together
    all of the images that I might have.
  • 2:49 - 2:51
    As you see in this case, I am pulling in,
  • 2:52 - 2:58
    and each of these at the very lefthand
    side of the file defines a service.
  • 2:58 - 3:00
    So I have db and a web,
  • 3:00 - 3:04
    and those are just names that I chose
    myself.
  • 3:04 - 3:08
    What follows is the definition of this
    service.
  • 3:08 - 3:10
    I have here an image,
  • 3:10 - 3:13
    which is Mongo, this is referring to that
    DockerHub Mongo.
  • 3:13 - 3:15
    It's going to pull it down.
  • 3:15 - 3:18
    And then I'm going to expose a couple
    of ports.
  • 3:18 - 3:21
    One of it is for the inside, the other
    one's for the outside,
  • 3:21 - 3:24
    and if it crashes, I want it to restart.
  • 3:24 - 3:26
    This is, by the way, the default port.
  • 3:26 - 3:29
    I then do something similar for the web,
  • 3:29 - 3:31
    and this is referring to that Dockerfile.
  • 3:31 - 3:33
    So I'm first going build it.
  • 3:33 - 3:35
    I'm going to bring in that image, as you
    saw.
  • 3:35 - 3:39
    And then it's going to run all of those
    commands.
  • 3:39 - 3:45
    Once it's done, I'm simply mapping my
    local directory system
  • 3:45 - 3:49
    to overlay on the internal one,
  • 3:49 - 3:51
    and I do that simply so I don't have to go
    into the container.
  • 3:52 - 3:55
    I map my ports, in this case,
    I want it to run on port 3000.
  • 3:56 - 4:02
    I then link to the database so that I can
    see it from the Dock,
  • 4:02 - 4:04
    from the Node.js side of things,
  • 4:04 - 4:07
    and then at the very end I simply run a
    command,
  • 4:08 - 4:09
    which is nodemon.
  • 4:09 - 4:13
    It's that node monitor npm package
  • 4:13 - 4:17
    that allows me to run a Node application.
  • 4:17 - 4:21
    And it simply reloads it every single time
    I do an edit.
  • 4:21 - 4:23
    So that is the definition of my files.
Title:
Module 3, Video 7
Video Language:
English
Duration:
04:27
julietteerath1 edited English subtitles for Module 3, Video 7
julietteerath1 edited English subtitles for Module 3, Video 7
julietteerath1 edited English subtitles for Module 3, Video 7

English subtitles

Revisions