• Stars
    star
    762
  • Rank 59,447 (Top 2 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Docker Compose for Node projects with Node, MySQL, Redis, MongoDB, NGINX, Apache2, Memcached, Certbot and RabbitMQ images

NoDock

Docker Compose for Node projects with Node, MySQL, MongoDB, NGINX, Memcached, Redis, Certbot and RabbitMQ images

Node + Docker

Why NoDock?

The docker Node.js image is very simple, you give it an entrypoint and it runs it. This is fine for very simple/small scripts but for larger projects you'll probably want something a bit more robust.

The goal of NoDock is to provide a complete environment for your node project: Node.js service(s), databases, web servers, queues, etc. while doing the "wiring" for you.

You can use NoDock for simple projects by using one of the examples or you can build upon them.

Contents

Requirements

Installation

As a git submodule:

git submodule add https://github.com/Osedea/nodock.git

Clone into your project:

git clone https://github.com/Osedea/nodock.git

We recommend you fork this repository if you intend to add project specific scripts/configurations.

Usage

cd nodock
# Run "node" and "nginx"
docker-compose up -d node nginx

To overwrite the docker-compose.yml file you can use a docker-compose.override.yml

# docker-compose.override.yml

version: '3'

services:
    [...]

Examples

We provide examples of configurations you might use for a specific stack. Each example has it's own README file with instructions.

Workspace

The workspace container is where you want to be manually running commands for NoDock. You can use this container to initialize your project, for task-automation, for cronjobs, etc.

Using HTTPS

By default HTTPS is disabled. To enable it, you may use the following settings

# docker-compose.override.yml
[...]
    nginx:
        build:
            args:
                - WEB_SSL=true

Add your certificate to nginx/certs/cacert.pem and the private key to nginx/certs/privkey.pem.

Generate and use a self-signed cert

SELF_SIGNED: "true" will generate the necessary files, do note that SELF_SIGNED: "true" as no effect if WEB_SSL: "false"

# docker-compose.override.yml
[...]
    nginx:
        build:
            args:
                - WEB_SSL=true
                - SELF_SIGNED=true

Use Certbot (Let's Encrypt) to generate the cert

CN must be a publicly accessible address and EMAIL should be the server admin contact email.

# docker-compose.override.yml
[...]
    nginx:
        build:
            args:
                - WEB_SSL=true
    certbot:
        environment:
            - CN=example.com
            - [email protected]

Don't forget to bring up the container if you plan on using certbot (docker-compose up -d certbot).

Running a single non-web container

The default NGINX server block configuration is aimed at web projects but if you want to have a single non-web container you can do something similar to the following configuration.

# docker-compose.override.yml
[...]
    nginx:
        build:
            args:
                -NO_DEFAULT=true
        ports:
            - "10000:10000"

Do note that using NO_DEFAULT makes WEB_REVERSE_PROXY_PORT, WEB_SSL and SELF_SIGNED have no effect.

You will then have to provide your own NGINX server block like so

# nginx/sites/custom-node.conf

server {
    listen 10000 default_server;

    location / {
        proxy_pass http://node:5000;
    }
}

Running multiple node containers

To add more node containers, simply add the following to your docker-compose.override.yml or environment specific docker-compose file.

# docker-compose.override.yml
[...]
    node2: # name of new container
        build:  # reuse the same values from the node service, cannot use extends in docker-compose 3+
            context: ./node
            args:
                - NODE_VERSION=latest
                - PROJECT_PATH=/opt/app/
                - NODE_ENV=production
                - YARN=false
        volumes:
            - ../:/opt/app
        entrypoint: run-nodock "node alternate.js" # the entrypoint for the "node2" container
    nginx:
        ports:
            - "10000:10000" # the port(s) to forward for the "node2" container
        links:
            - node2 # link "nginx" to "node2"

You'll also need to add a server block for "node2".

# nginx/sites/node2.conf

server {
    listen 10000 default_server;

    location / {
        proxy_pass http://node2:8000;
    }
}

Cronjobs

You can run cronjobs in the Workspace by storing them in the workspace/crontab/root file.

# workspace/crontab/root

* * * * * echo "Every Minute" >> /var/log/cron.log

More Options

To customize the NoDock installation, either add a docker-compose.override.yml in the NoDock directory or store environment specific configurations.

docker-compose -f nodock/docker-compose.yml -f docker-compose.dev.yml up -d

Use Yarn

Set the YARN argument to true.

# docker-compose.override.yml
[...]
    node:
        build:
            args:
                - YARN=true

Change the node entrypoint

Use main.js instead of index.js

# docker-compose.override.yml
[...]
    node:
        entrypoint: run-nodock "node main.js"

Change the Node Environment

The default NODE_ENV value is production, you can change it to development by doing the following

# docker-compose.override.yml
[...]
    node:
        build:
            args:
                - NODE_ENV=development

Use a specific Node version

The default node version is latest, this is NOT advisable for production

# docker-compose.override.yml
[...]
    node:
        build:
            args:
                - NODE_VERSION=4.6.0

Change the Node project path

You can specify a PROJECT_PATH to change the directory in which npm will perform it's install command and the directory in which run-nodock will run the entrypoint script. This is most desirable when running more than one Node project at a time since they are bound to each have their own package.json file.

# docker-compose.override.yml
[...]
    node:
        build:
            args:
                PROJECT_PATH: somefolder # note that this is the same as "/opt/app/somefolder"

Change the MySQL database/user/password

# docker-compose.override.yml
[...]
    mysql:
        build:
            args:
                - MYSQL_DATABASE=default_database
                - MYSQL_USER=default_user
                - MYSQL_PASSWORD=secret

Change the PostgreSQL database/user/password

# docker-compose.override.yml
[...]
    postgresql:
        build:
            args:
                - POSTGRES_DB=default_db
                - POSTGRES_USER=default_user
                - POSTGRES_PASSWORD=secret

Change the NGINX reverse proxy port

Use port 8080 instead of 8000 to bind your Node server

# docker-compose.override.yml
[...]
    nginx:
        build:
            args:
                - WEB_REVERSE_PROXY_PORT=8080

Change the timezone

To change the timezone for the workspace container, modify the TZ build argument in the Docker Compose file to one in the TZ database.

For example, if I want the timezone to be New York:

# docker-compose.override.yml
[...]
     workspace:
        build:
            context: ./workspace
            args:
                - TZ="America/New_York"

Use RabbitMQ plugins

At the moment, NoDock supports 2 plugins: Management and Federation.

To activate them, change their values to true in your docker-compose file:

# docker-compose.override.yml
[...]
    rabbitmq:
        build:
            args:
                - MANAGEMENT=true
                - FEDERATION=true

Change the RabbitMQ user/password

# docker-compose.override.yml
[...]
    rabbitmq:
        build:
            args:
                - RABBITMQ_DEFAULT_USER=custom_user
                - RABBITMQ_DEFAULT_PASS=custom_pass

Modify the Redis config

You can edit redis/redis.conf to modify the redis config.

Contributing

Do not hesitate to contribute to NoDock by creating an issue, fixing a bug or bringing a new idea to the table.

To fix a bug or introduce a new feature, please create a PR, we will merge it in to the master branch after review.

We thank you in advance for contributing.

License

MIT License (MIT)

Credits

NoDock uses Open Source components. You can find the source code of their open source projects along with license information below. We acknowledge and are grateful to these developers for their contributions to open source.

Project: LaraDock https://github.com/LaraDock/laradock
Copyright (c) 2016 Mahmoud Zalt ([email protected])
License (MIT) https://github.com/LaraDock/laradock/blob/master/LICENSE

Project: baseimage-docker https://github.com/phusion/baseimage-docker
Copyright (c) 2013-2015 Phusion Holding B.V.
License (MIT) https://github.com/phusion/baseimage-docker/blob/master/LICENSE.txt

More Repositories

1

react-native-offline-first-example

Example App using best practices for React Native offline (InstaMeow) presented at React Native EU 2017
JavaScript
80
star
2

react-native-action-bar

An Android-like action bar for react-native
JavaScript
58
star
3

react-native-interactive-avatar

An avatar allowing you to click on it to change the image
JavaScript
48
star
4

react-native-opengraph-kit

A set of components and utils useful to extract opengraph data directly from your react-native app
JavaScript
46
star
5

redux-persist-realm

A Realmjs interface for redux-persist
JavaScript
39
star
6

react-native-osd-datetimepicker

A Datepicker for Android and iOs for react-native
JavaScript
23
star
7

laravel-rest

A bundle providing a RESTful API for the Laravel framework version 5 using the command bus.
PHP
20
star
8

angular-osd-resource

Create resources and decorators from a config file
JavaScript
18
star
9

react-native-navigation-examples

A set of examples created for a Montreal React Native meetup talk : https://www.meetup.com/fr-FR/React-Native-MTL/events/248410421/
Objective-C
13
star
10

react-native-osd-simple-button

A button that implement most of the HTML attributes and flexes itself (that is not a word)
JavaScript
9
star
11

angular-osd-opentok

An implementation of Opentok's WebRTC library made for AngularJS
JavaScript
8
star
12

angular-osd-form

A form validation directive in AngularJS
JavaScript
8
star
13

react-native-redux-rest-resource

A helper to handle REST Apis with Redux in react-native
JavaScript
7
star
14

ionic-sample-hacker-news

JavaScript
7
star
15

angular-osd-upload

An upload service to simplify file validations and upload.
JavaScript
6
star
16

react-native-plus-button-box

A component to display an Android-like "+" button and display action items
JavaScript
6
star
17

osd-atom-snippets

Snippets we use at Osedea
CoffeeScript
6
star
18

angular-osd-auth

An angular module to authenticate an user using $http.
JavaScript
4
star
19

react-native-osd-form

Our take on building a react-native "Form" component
JavaScript
4
star
20

ignite-crashlytics

An ignite plugin to add Fabric and Crashlytics to your react-native app
JavaScript
4
star
21

zf2-osd-entity

A base class that provides some default functions for zf2 entity classes.
PHP
3
star
22

st-henri-scoreboard

Training Project for St-Henri High School
JavaScript
3
star
23

Soccer-Cool

Training Project for St-Henri High School A2016
JavaScript
3
star
24

react-native-offline-first-example-backend

A simple feathers backend for react-native-offline-first-example
HTML
3
star
25

ignite-native-navigation

JavaScript
3
star
26

ignite-osd-generators

Ignite generators for Osedea React Native projects
JavaScript
2
star
27

ignite-navigation

Ignite plugin to add react-navigation
JavaScript
2
star
28

zf2-osd-encrypt

A zf2/doctrine module for encryption
PHP
2
star
29

ignite-code-push

Ignite plugin to add code push to a React Native application
JavaScript
2
star
30

tech-links

Osedea Tech Links - An archive of shared knowledge in the form of links to various topics and teachings in Technology, News and Science.
2
star
31

osedea_project_welcome-email_assets

Assets for osedea_project_welcome-email which are served via a GitHub page
1
star
32

ignite-splashscreen

Ignite plugin to add a splashscreen easily
JavaScript
1
star
33

data-cleaning-with-pandas

Jupyter notebooks and datasets for Python data cleaning tutorial
Jupyter Notebook
1
star
34

directus_docker_getting-started

The repository companion to a Medium article about getting started with Directus and Docker
PHP
1
star