|
@@ -10,14 +10,11 @@ parent = "smn_applied"
|
|
|
|
|
|
# Dockerizing a Node.js web app
|
|
# Dockerizing a Node.js web app
|
|
|
|
|
|
-> **Note**:
|
|
|
|
-> - **If you don't like sudo** then see [*Giving non-root
|
|
|
|
-> access*](/installation/binaries/#giving-non-root-access)
|
|
|
|
-
|
|
|
|
-The goal of this example is to show you how you can build your own
|
|
|
|
-Docker images from a parent image using a `Dockerfile`
|
|
|
|
-. We will do that by making a simple Node.js hello world web
|
|
|
|
-application running on CentOS. You can get the full source code at
|
|
|
|
|
|
+> **Note**: **If you don't like sudo** then see [*Giving non-root
|
|
|
|
+> access*](/installation/binaries/#giving-non-root-access)
|
|
|
|
+
|
|
|
|
+In this example, we are going to learn how to build a Docker image to run a
|
|
|
|
+simple Node.js "hello world" web application on CentOS. You can get the full source code at
|
|
[https://github.com/enokd/docker-node-hello/](https://github.com/enokd/docker-node-hello/).
|
|
[https://github.com/enokd/docker-node-hello/](https://github.com/enokd/docker-node-hello/).
|
|
|
|
|
|
## Create Node.js app
|
|
## Create Node.js app
|
|
@@ -75,16 +72,16 @@ available on the [Docker Hub](https://hub.docker.com/):
|
|
|
|
|
|
Since we're building a Node.js app, you'll have to install Node.js as
|
|
Since we're building a Node.js app, you'll have to install Node.js as
|
|
well as npm on your CentOS image. Node.js is required to run your app
|
|
well as npm on your CentOS image. Node.js is required to run your app
|
|
-and npm to install your app's dependencies defined in
|
|
|
|
|
|
+and npm is required to install your app's dependencies defined in
|
|
`package.json`. To install the right package for
|
|
`package.json`. To install the right package for
|
|
CentOS, we'll use the instructions from the [Node.js wiki](
|
|
CentOS, we'll use the instructions from the [Node.js wiki](
|
|
https://github.com/joyent/node/wiki/Installing-Node.js-
|
|
https://github.com/joyent/node/wiki/Installing-Node.js-
|
|
via-package-manager#rhelcentosscientific-linux-6):
|
|
via-package-manager#rhelcentosscientific-linux-6):
|
|
|
|
|
|
- # Enable EPEL for Node.js
|
|
|
|
- RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
|
|
|
|
|
|
+ # Enable Extra Packages for Enterprise Linux (EPEL) for CentOS
|
|
|
|
+ RUN yum install -y epel-release
|
|
# Install Node.js and npm
|
|
# Install Node.js and npm
|
|
- RUN yum install -y npm
|
|
|
|
|
|
+ RUN yum install -y nodejs npm
|
|
|
|
|
|
To bundle your app's source code inside the Docker image, use the `COPY`
|
|
To bundle your app's source code inside the Docker image, use the `COPY`
|
|
instruction:
|
|
instruction:
|
|
@@ -97,7 +94,7 @@ Install your app dependencies using the `npm` binary:
|
|
# Install app dependencies
|
|
# Install app dependencies
|
|
RUN cd /src; npm install
|
|
RUN cd /src; npm install
|
|
|
|
|
|
-Your app binds to port `8080` so you'll use the` EXPOSE` instruction to have
|
|
|
|
|
|
+Your app binds to port `8080` so you'll use the `EXPOSE` instruction to have
|
|
it mapped by the `docker` daemon:
|
|
it mapped by the `docker` daemon:
|
|
|
|
|
|
EXPOSE 8080
|
|
EXPOSE 8080
|
|
@@ -112,10 +109,10 @@ Your `Dockerfile` should now look like this:
|
|
|
|
|
|
FROM centos:centos6
|
|
FROM centos:centos6
|
|
|
|
|
|
- # Enable EPEL for Node.js
|
|
|
|
- RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
|
|
|
|
|
|
+ # Enable Extra Packages for Enterprise Linux (EPEL) for CentOS
|
|
|
|
+ RUN yum install -y epel-release
|
|
# Install Node.js and npm
|
|
# Install Node.js and npm
|
|
- RUN yum install -y npm
|
|
|
|
|
|
+ RUN yum install -y nodejs npm
|
|
|
|
|
|
# Bundle app source
|
|
# Bundle app source
|
|
COPY . /src
|
|
COPY . /src
|