* Documentation: Deploying a Node.js Web App on CentOS
* Documentation: small formatting improvements
... | ... |
@@ -6,6 +6,7 @@ SPHINXOPTS = |
6 | 6 |
SPHINXBUILD = sphinx-build |
7 | 7 |
PAPER = |
8 | 8 |
BUILDDIR = _build |
9 |
+PYTHON = python |
|
9 | 10 |
|
10 | 11 |
# Internal variables. |
11 | 12 |
PAPEROPT_a4 = -D latex_paper_size=a4 |
... | ... |
@@ -38,6 +39,7 @@ help: |
38 | 38 |
# @echo " linkcheck to check all external links for integrity" |
39 | 39 |
# @echo " doctest to run all doctests embedded in the documentation (if enabled)" |
40 | 40 |
@echo " docs to build the docs and copy the static files to the outputdir" |
41 |
+ @echo " server to serve the docs in your browser under \`http://localhost:8000\`" |
|
41 | 42 |
@echo " publish to publish the app to dotcloud" |
42 | 43 |
|
43 | 44 |
clean: |
... | ... |
@@ -49,6 +51,8 @@ docs: |
49 | 49 |
@echo |
50 | 50 |
@echo "Build finished. The documentation pages are now in $(BUILDDIR)/html." |
51 | 51 |
|
52 |
+server: |
|
53 |
+ @cd $(BUILDDIR)/html; $(PYTHON) -m SimpleHTTPServer 8000 |
|
52 | 54 |
|
53 | 55 |
site: |
54 | 56 |
cp -r website $(BUILDDIR)/ |
... | ... |
@@ -14,20 +14,22 @@ Installation |
14 | 14 |
------------ |
15 | 15 |
|
16 | 16 |
* Work in your own fork of the code, we accept pull requests. |
17 |
-* Install sphinx: ``pip install sphinx`` |
|
18 |
-* Install sphinx httpdomain contrib package ``sphinxcontrib-httpdomain`` |
|
17 |
+* Install sphinx: `pip install sphinx` |
|
18 |
+ * Mac OS X: `[sudo] pip-2.7 install sphinx`) |
|
19 |
+* Install sphinx httpdomain contrib package: `pip install sphinxcontrib-httpdomain` |
|
20 |
+ * Mac OS X: `[sudo] pip-2.7 install sphinxcontrib-httpdomain` |
|
19 | 21 |
* If pip is not available you can probably install it using your favorite package manager as **python-pip** |
20 | 22 |
|
21 | 23 |
Usage |
22 | 24 |
----- |
23 |
-* change the .rst files with your favorite editor to your liking |
|
24 |
-* run *make docs* to clean up old files and generate new ones |
|
25 |
-* your static website can now be found in the _build dir |
|
26 |
-* to preview what you have generated, cd into _build/html and then run 'python -m SimpleHTTPServer 8000' |
|
25 |
+* Change the `.rst` files with your favorite editor to your liking. |
|
26 |
+* Run `make docs` to clean up old files and generate new ones. |
|
27 |
+* Your static website can now be found in the `_build` directory. |
|
28 |
+* To preview what you have generated run `make server` and open <http://localhost:8000/> in your favorite browser. |
|
27 | 29 |
|
28 |
-Working using github's file editor |
|
30 |
+Working using GitHub's file editor |
|
29 | 31 |
---------------------------------- |
30 |
-Alternatively, for small changes and typo's you might want to use github's built in file editor. It allows |
|
32 |
+Alternatively, for small changes and typo's you might want to use GitHub's built in file editor. It allows |
|
31 | 33 |
you to preview your changes right online. Just be carefull not to create many commits. |
32 | 34 |
|
33 | 35 |
Images |
... | ... |
@@ -72,4 +74,4 @@ Guides on using sphinx |
72 | 72 |
|
73 | 73 |
* Code examples |
74 | 74 |
|
75 |
- Start without $, so it's easy to copy and paste. |
|
76 | 75 |
\ No newline at end of file |
76 |
+ Start without $, so it's easy to copy and paste. |
... | ... |
@@ -5,8 +5,8 @@ |
5 | 5 |
Introduction |
6 | 6 |
============ |
7 | 7 |
|
8 |
-Docker - The Linux container runtime |
|
8 |
+Docker -- The Linux container runtime |
|
9 |
+------------------------------------- |
|
9 | 10 |
|
10 | 11 |
Docker complements LXC with a high-level API which operates at the process level. It runs unix processes with strong guarantees of isolation and repeatability across servers. |
11 | 12 |
|
... | ... |
@@ -1,8 +1,8 @@ |
1 |
-:title: Setting up a dev environment |
|
1 |
+:title: Setting Up a Dev Environment |
|
2 | 2 |
:description: Guides on how to contribute to docker |
3 | 3 |
:keywords: Docker, documentation, developers, contributing, dev environment |
4 | 4 |
|
5 |
-Setting up a dev environment |
|
5 |
+Setting Up a Dev Environment |
|
6 | 6 |
============================ |
7 | 7 |
|
8 | 8 |
Instructions that have been verified to work on Ubuntu 12.10, |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
:title: Docker Examples |
2 | 2 |
:description: Examples on how to use Docker |
3 |
-:keywords: docker, hello world, examples |
|
3 |
+:keywords: docker, hello world, node, nodejs, python, couch, couchdb, redis, ssh, sshd, examples |
|
4 | 4 |
|
5 | 5 |
|
6 | 6 |
|
... | ... |
@@ -16,6 +16,7 @@ Contents: |
16 | 16 |
hello_world |
17 | 17 |
hello_world_daemon |
18 | 18 |
python_web_app |
19 |
+ nodejs_web_app |
|
19 | 20 |
running_redis_service |
20 | 21 |
running_ssh_service |
21 | 22 |
couchdb_data_volumes |
22 | 23 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,236 @@ |
0 |
+:title: Running a Node.js app on CentOS |
|
1 |
+:description: Installing and running a Node.js app on CentOS |
|
2 |
+:keywords: docker, example, package installation, node, centos |
|
3 |
+ |
|
4 |
+.. _nodejs_web_app: |
|
5 |
+ |
|
6 |
+Node.js Web App |
|
7 |
+=============== |
|
8 |
+ |
|
9 |
+.. include:: example_header.inc |
|
10 |
+ |
|
11 |
+The goal of this example is to show you how you can build your own docker images |
|
12 |
+from a parent image using a ``Dockerfile`` . We will do that by making a simple |
|
13 |
+Node.js hello world web application running on CentOS. You can get the full |
|
14 |
+source code at https://github.com/gasi/docker-node-hello. |
|
15 |
+ |
|
16 |
+Create Node.js app |
|
17 |
+ |
|
18 |
+First, create a ``package.json`` file that describes your app and its |
|
19 |
+dependencies: |
|
20 |
+ |
|
21 |
+.. code-block:: json |
|
22 |
+ |
|
23 |
+ { |
|
24 |
+ "name": "docker-centos-hello", |
|
25 |
+ "private": true, |
|
26 |
+ "version": "0.0.1", |
|
27 |
+ "description": "Node.js Hello World app on CentOS using docker", |
|
28 |
+ "author": "Daniel Gasienica <daniel@gasienica.ch>", |
|
29 |
+ "dependencies": { |
|
30 |
+ "express": "3.2.4" |
|
31 |
+ } |
|
32 |
+ } |
|
33 |
+ |
|
34 |
+Then, create an ``index.js`` file that defines a web app using the |
|
35 |
+`Express.js <http://expressjs.com/>`_ framework: |
|
36 |
+ |
|
37 |
+.. code-block:: javascript |
|
38 |
+ |
|
39 |
+ var express = require('express'); |
|
40 |
+ |
|
41 |
+ // Constants |
|
42 |
+ var PORT = 8080; |
|
43 |
+ |
|
44 |
+ // App |
|
45 |
+ var app = express(); |
|
46 |
+ app.get('/', function (req, res) { |
|
47 |
+ res.send('Hello World\n'); |
|
48 |
+ }); |
|
49 |
+ |
|
50 |
+ app.listen(PORT) |
|
51 |
+ console.log('Running on http://localhost:' + PORT); |
|
52 |
+ |
|
53 |
+ |
|
54 |
+In the next steps, we’ll look at how you can run this app inside a CentOS |
|
55 |
+container using docker. First, you’ll need to build a docker image of your app. |
|
56 |
+ |
|
57 |
+Creating a ``Dockerfile`` |
|
58 |
+ |
|
59 |
+Create an empty file called ``Dockerfile``: |
|
60 |
+ |
|
61 |
+.. code-block:: bash |
|
62 |
+ |
|
63 |
+ touch Dockerfile |
|
64 |
+ |
|
65 |
+Open the ``Dockerfile`` in your favorite text editor and add the following line |
|
66 |
+that defines the version of docker the image requires to build |
|
67 |
+(this example uses docker 0.3.4): |
|
68 |
+ |
|
69 |
+.. code-block:: bash |
|
70 |
+ |
|
71 |
+ # DOCKER-VERSION 0.3.4 |
|
72 |
+ |
|
73 |
+Next, define the parent image you want to use to build your own image on top of. |
|
74 |
+Here, we’ll use `CentOS <https://index.docker.io/_/centos/>`_ (tag: ``6.4``) |
|
75 |
+available on the `docker index`_: |
|
76 |
+ |
|
77 |
+.. code-block:: bash |
|
78 |
+ |
|
79 |
+ FROM centos:6.4 |
|
80 |
+ |
|
81 |
+Since we’re building a Node.js app, you’ll have to install Node.js as well as |
|
82 |
+npm on your CentOS image. Node.js is required to run your app and npm to install |
|
83 |
+your app’s dependencies defined in ``package.json``. |
|
84 |
+To install the right package for CentOS, we’ll use the instructions from the |
|
85 |
+`Node.js wiki`_: |
|
86 |
+ |
|
87 |
+.. code-block:: bash |
|
88 |
+ |
|
89 |
+ # Enable EPEL for Node.js |
|
90 |
+ RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm |
|
91 |
+ # Install Node.js and npm |
|
92 |
+ RUN yum install -y npm-1.2.17-5.el6 |
|
93 |
+ |
|
94 |
+To bundle your app’s source code inside the docker image, use the ``ADD`` |
|
95 |
+command: |
|
96 |
+ |
|
97 |
+.. code-block:: bash |
|
98 |
+ |
|
99 |
+ # Bundle app source |
|
100 |
+ ADD . /src |
|
101 |
+ |
|
102 |
+Install your app dependencies using npm: |
|
103 |
+ |
|
104 |
+.. code-block:: bash |
|
105 |
+ |
|
106 |
+ # Install app dependencies |
|
107 |
+ RUN cd /src; npm install |
|
108 |
+ |
|
109 |
+Your app binds to port ``8080`` so you’ll use the ``EXPOSE`` command to have it |
|
110 |
+mapped by the docker daemon: |
|
111 |
+ |
|
112 |
+.. code-block:: bash |
|
113 |
+ |
|
114 |
+ EXPOSE 8080 |
|
115 |
+ |
|
116 |
+Last but not least, define the command to run your app using ``CMD`` which |
|
117 |
+defines your runtime, i.e. ``node``, and the path to our app, i.e. |
|
118 |
+``src/index.js`` (see the step where we added the source to the container): |
|
119 |
+ |
|
120 |
+.. code-block:: bash |
|
121 |
+ |
|
122 |
+ CMD ["node", "/src/index.js"] |
|
123 |
+ |
|
124 |
+Your ``Dockerfile`` should now look like this: |
|
125 |
+ |
|
126 |
+.. code-block:: bash |
|
127 |
+ |
|
128 |
+ |
|
129 |
+ # DOCKER-VERSION 0.3.4 |
|
130 |
+ FROM centos:6.4 |
|
131 |
+ |
|
132 |
+ # Enable EPEL for Node.js |
|
133 |
+ RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm |
|
134 |
+ # Install Node.js and npm |
|
135 |
+ RUN yum install -y npm-1.2.17-5.el6 |
|
136 |
+ |
|
137 |
+ # Bundle app source |
|
138 |
+ ADD . /src |
|
139 |
+ # Install app dependencies |
|
140 |
+ RUN cd /src; npm install |
|
141 |
+ |
|
142 |
+ EXPOSE 8080 |
|
143 |
+ CMD ["node", "/src/index.js"] |
|
144 |
+ |
|
145 |
+ |
|
146 |
+Building your image |
|
147 |
+ |
|
148 |
+Go to the directory that has your ``Dockerfile`` and run the following command |
|
149 |
+to build a docker image. The ``-t`` flag let’s you tag your image so it’s easier |
|
150 |
+to find later using the ``docker images`` command: |
|
151 |
+ |
|
152 |
+.. code-block:: bash |
|
153 |
+ |
|
154 |
+ docker build -t <your username>/centos-node-hello . |
|
155 |
+ |
|
156 |
+Your image will now be listed by docker: |
|
157 |
+ |
|
158 |
+.. code-block:: bash |
|
159 |
+ |
|
160 |
+ docker images |
|
161 |
+ |
|
162 |
+ > # Example |
|
163 |
+ > REPOSITORY TAG ID CREATED |
|
164 |
+ > centos 6.4 539c0211cd76 8 weeks ago |
|
165 |
+ > gasi/centos-node-hello latest d64d3505b0d2 2 hours ago |
|
166 |
+ |
|
167 |
+ |
|
168 |
+Run the image |
|
169 |
+ |
|
170 |
+Running your image with ``-d`` runs the container in detached mode, leaving the |
|
171 |
+container running in the background. Run the image you previously built: |
|
172 |
+ |
|
173 |
+.. code-block:: bash |
|
174 |
+ |
|
175 |
+ docker run -d <your username>/centos-node-hello |
|
176 |
+ |
|
177 |
+Print the output of your app: |
|
178 |
+ |
|
179 |
+.. code-block:: bash |
|
180 |
+ |
|
181 |
+ # Get container ID |
|
182 |
+ docker ps |
|
183 |
+ |
|
184 |
+ # Print app output |
|
185 |
+ docker logs <container id> |
|
186 |
+ |
|
187 |
+ > # Example |
|
188 |
+ > Running on http://localhost:8080 |
|
189 |
+ |
|
190 |
+ |
|
191 |
+Test |
|
192 |
+ |
|
193 |
+To test your app, get the the port of your app that docker mapped: |
|
194 |
+ |
|
195 |
+.. code-block:: bash |
|
196 |
+ |
|
197 |
+ docker ps |
|
198 |
+ |
|
199 |
+ > # Example |
|
200 |
+ > ID IMAGE COMMAND ... PORTS |
|
201 |
+ > ecce33b30ebf gasi/centos-node-hello:latest node /src/index.js 49160->8080 |
|
202 |
+ |
|
203 |
+In the example above, docker mapped the ``8080`` port of the container to |
|
204 |
+``49160``. |
|
205 |
+ |
|
206 |
+Now you can call your app using ``curl`` (install if needed via: |
|
207 |
+``sudo apt-get install curl``): |
|
208 |
+ |
|
209 |
+.. code-block:: bash |
|
210 |
+ |
|
211 |
+ curl -i localhost:49160 |
|
212 |
+ |
|
213 |
+ > HTTP/1.1 200 OK |
|
214 |
+ > X-Powered-By: Express |
|
215 |
+ > Content-Type: text/html; charset=utf-8 |
|
216 |
+ > Content-Length: 12 |
|
217 |
+ > Date: Sun, 02 Jun 2013 03:53:22 GMT |
|
218 |
+ > Connection: keep-alive |
|
219 |
+ > |
|
220 |
+ > Hello World |
|
221 |
+ |
|
222 |
+We hope this tutorial helped you get up and running with Node.js and CentOS on |
|
223 |
+docker. You can get the full source code at |
|
224 |
+https://github.com/gasi/docker-node-hello. |
|
225 |
+ |
|
226 |
+Continue to :ref:`running_redis_service`. |
|
227 |
+ |
|
228 |
+ |
|
229 |
+.. _Node.js wiki: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#rhelcentosscientific-linux-6 |
|
230 |
+.. _docker index: https://index.docker.io/ |
... | ... |
@@ -7,8 +7,8 @@ |
7 | 7 |
Introduction |
8 | 8 |
============ |
9 | 9 |
|
10 |
-Docker - The Linux container runtime |
|
10 |
+Docker -- The Linux container runtime |
|
11 |
+------------------------------------- |
|
11 | 12 |
|
12 | 13 |
Docker complements LXC with a high-level API which operates at the process level. It runs unix processes with strong guarantees of isolation and repeatability across servers. |
13 | 14 |
|
... | ... |
@@ -4,8 +4,8 @@ |
4 | 4 |
|
5 | 5 |
.. _working_with_the_repository: |
6 | 6 |
|
7 |
-Working with the repository |
|
8 |
-============================ |
|
7 |
+Working with the Repository |
|
8 |
+=========================== |
|
9 | 9 |
|
10 | 10 |
|
11 | 11 |
Top-level repositories and user repositories |
... | ... |
@@ -14,9 +14,9 @@ Top-level repositories and user repositories |
14 | 14 |
Generally, there are two types of repositories: Top-level repositories which are controlled by the people behind |
15 | 15 |
Docker, and user repositories. |
16 | 16 |
|
17 |
-* Top-level repositories can easily be recognized by not having a / (slash) in their name. These repositories can |
|
17 |
+* Top-level repositories can easily be recognized by not having a ``/`` (slash) in their name. These repositories can |
|
18 | 18 |
generally be trusted. |
19 |
-* User repositories always come in the form of <username>/<repo_name>. This is what your published images will look like. |
|
19 |
+* User repositories always come in the form of ``<username>/<repo_name>``. This is what your published images will look like. |
|
20 | 20 |
* User images are not checked, it is therefore up to you whether or not you trust the creator of this image. |
21 | 21 |
|
22 | 22 |
|