You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47-16
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
## Introduction
2
-
This is a Dockerfile to build a container image for nginx and php-fpm, with the ability to pull website code from git. The container can also use environment variables to configure your web application using the templating detailed in the special features section.
2
+
This is a Dockerfile to build a container image for nginx and nodejs, with the ability to pull website code from git. The container can also use environment variables to configure your web application using the templating detailed in the special features section.
3
3
4
4
### Git reposiory
5
-
The source files for this project can be found here: [https://github.com/ngineered/nginx-php-fpm](https://github.com/ngineered/nginx-php-fpm)
5
+
The source files for this project can be found here: [https://github.com/ngineered/nginx-nodejs](https://github.com/ngineered/nginx-nodejs)
6
6
7
7
If you have any improvements please submit a pull request.
8
8
9
9
### Docker hub repository
10
-
The Docker hub build can be found here: [https://registry.hub.docker.com/u/richarvey/nginx-php-fpm/](https://registry.hub.docker.com/u/richarvey/nginx-php-fpm/)
10
+
The Docker hub build can be found here: [https://registry.hub.docker.com/u/richarvey/nginx-nodejs/](https://registry.hub.docker.com/u/richarvey/nginx-nodejs/)
11
11
12
12
## Nginx Versions
13
13
- Mainline Version: **1.7.9**
@@ -18,25 +18,60 @@ The Docker hub build can be found here: [https://registry.hub.docker.com/u/richa
18
18
Pull the image from the docker index rather than downloading the git repo. This prevents you having to build the image on every docker host.
19
19
20
20
```
21
-
docker pull richarvey/nginx-pfp-fpm:latest
21
+
docker pull richarvey/nginx-nodejs:latest
22
22
```
23
23
To pull the Stable Version:
24
24
25
25
```
26
-
docker pull richarvey/nginx-pfp-fpm:stable
26
+
docker pull richarvey/nginx-nodejs:stable
27
27
```
28
28
## Running
29
29
To simply run the container:
30
30
31
31
```
32
-
sudo docker run --name nginx -p 8080:80 -d richarvey/nginx-php-fpm
32
+
sudo docker run --name nginx -p 8080:80 -d richarvey/nginx-nodejs
33
33
```
34
34
You can then browse to http://<docker_host>:8080 to view the default install files.
35
+
### Running your nodeJS app and default port
36
+
The container will automatically run any file in the */usr/share/nginx/html* directory named server.js, so if you are pulling your own code from git be sure to name your application *server.js*.
37
+
38
+
Nginx is set to listen for your application on port 3000 on the localhost. So make sure you set your node app to run on port 3000:
39
+
40
+
```
41
+
var server = app.listen(3000, function () {
42
+
...
43
+
```
44
+
45
+
To view your application you can go to:
46
+
```
47
+
http://<docker_ip>:8080
48
+
```
49
+
### Serving Static Content from Nginx
50
+
By placing files in the */usr/share/nginx/html/public* directory nginx will serve the static files directly. You can then browse the files directly:
51
+
52
+
Example:
53
+
```
54
+
http://<docker_ip>:8080/public/ngineered.png
55
+
```
35
56
### Volumes
36
57
If you want to link to your web site directory on the docker host to the container run:
To install npm dependancies simply create a package.json file int he route of your code. The example below install express 4.x
64
+
65
+
```
66
+
{
67
+
"name": "node-server-example",
68
+
"description": "Hello World App",
69
+
"version": "0.0.1",
70
+
"private": true,
71
+
"dependencies": {
72
+
"express": "4.x"
73
+
}
74
+
}
40
75
```
41
76
### Pulling code from git
42
77
One of the nice features of this container is its ability to pull code from a git repository with a couple of environmental variables passed at run time.
@@ -46,13 +81,13 @@ One of the nice features of this container is its ability to pull code from a gi
46
81
To run the container and pull code simply specify the GIT_REPO URL including *git@* and then make sure you have a folder on the docker host with your id_rsa key stored in it:
As with all docker containers its possible to link resources from the host OS to the guest. This makes it really easy to link in custom nginx default config files or extra virtual hosts and SSL enabled sites. For SSL sites first create a directory somewhere such as */opt/deployname/ssl/*. In this directory drop you SSL cert and Key in. Next create a directory for your custom hosts such as */opt/deployname/sites-enabled*. In here load your custom default.conf file which references your SSL cert and keys at the location, for example: */etc/nginx/ssl/xxxx.key*
91
126
92
127
Then start your container and connect these volumes like so:
This will expose the following variables that can be used to template your code.
@@ -129,12 +162,10 @@ MYSQL_PASS=password
129
162
To use these variables in a template you'd do the following in your file:
130
163
131
164
```
132
-
<?php
133
165
database_host = $$_MYSQL_HOST_$$;
134
166
database_user = $$_MYSQL_USER_$$;
135
167
database_pass = $$_MYSQL_PASS_$$
136
168
...
137
-
?>
138
169
```
139
170
### Template anything
140
171
Yes ***ANYTHING***, any variable exposed by a linked container or the **-e** flag lets you template your config files. This means you can add redis, mariaDB, memcache or anything you want to your application very easily.
0 commit comments