Git Product home page Git Product logo

osedea / nodock Goto Github PK

View Code? Open in Web Editor NEW
761.0 44.0 188.0 383 KB

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

Home Page: http://nodock.io

License: MIT License

Shell 38.69% JavaScript 28.08% Dockerfile 33.23%
docker nodejs docker-compose docker-node docker-images node-nginx node-mysql rabbitmq certbot workspace

nodock's Introduction

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

nodock's People

Contributors

flightcom avatar mart-coul avatar philtrep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nodock's Issues

Persistent bash history

The bash history should be saved for the node and workspace containers to make it easier to reuse commands even if container is rebuilt.

MySQL bind-address option

We should never specify 0.0.0.0 as value for the the bind-address option.
We should find a way to replace 0.0.0.0 by other containers local IPs.

Support angular 5 hosted with nginx

My application is consisted of angular 5 client, nodejs api, mongo db, and nginx.

From my understanding, I should include my angular dist files in the nginx image, but I'm not sure.

What is the most suitable way to include my angular 5 dist files?

Caddy webserver

Caddy seems to be rising in popularity, it would be worthwhile to investigate integrating it with NoDock.

nginx 502 error

Hello,
I am currently using nodock and my node app is running inside the container on 8000.
Here's a response inside the container:
root@11757b94d64a:/opt/app# curl -I localhost:8000
HTTP/1.1 200 OK
cache-control: no-cache
Date: Fri, 23 Mar 2018 09:13:55 GMT
Connection: keep-alive

And on nginx container, I see this:
location / {
proxy_pass http://node:8000;
}

I don't have much experience in docker, and I am not sure why it's not working.
Also, I have modified the docker-composer file and removed the folders and it's configs that I don't need, could that be the problem?
Please let me know.
Shahriar

Simplify existing examples

Some of the examples have have few extra lines i.e. cp 2+ times.

We should simplify this to increase adoption.

Add redis service

Given the popularity of redis, would be worthwhile to have it added to the existing services.

Add PostgreSQL container

Add a PostgreSQL container, it's definitely popular enough to warrant the extra service.

We must also add an example on how to use it.

Error building nginx service

I get error when running the docker-compose up -d mongo node nginx command.
My OS: Windows 8.1
Terminal: Hyper

Here is the command's output:

$ docker-compose up -d mongo node nginx
Building nginx
Step 1/16 : FROM nginx:1.11
 ---> 5766334bdaa0
Step 2/16 : RUN mkdir /etc/nginx/sites-available && rm /etc/nginx/conf.d/default.conf
 ---> Using cache
 ---> 4892dddb739b
Step 3/16 : ADD nginx.conf /etc/nginx/
 ---> Using cache
 ---> 03b774e4cfd5
Step 4/16 : COPY scripts /root/scripts/
 ---> Using cache
 ---> 36c6047daf6a
Step 5/16 : COPY certs /etc/ssl/
 ---> Using cache
 ---> b90502ed266c
Step 6/16 : COPY sites /etc/nginx/templates
 ---> Using cache
 ---> 19c271ddb0af
Step 7/16 : ARG WEB_REVERSE_PROXY_PORT=8000
 ---> Using cache
 ---> f81484e144ab
Step 8/16 : ARG WEB_SSL=false
 ---> Using cache
 ---> c8811228c3df
Step 9/16 : ARG SELF_SIGNED=false
 ---> Using cache
 ---> dcfdad9868e4
Step 10/16 : ARG NO_DEFAULT=false
 ---> Using cache
 ---> ce8f9a09dc8b
Step 11/16 : ENV WEB_REVERSE_PROXY_PORT=$WEB_REVERSE_PROXY_PORT
 ---> Using cache
 ---> f917d6e76e24
Step 12/16 : ENV WEB_SSL=$WEB_SSL
 ---> Using cache
 ---> 302da37baf92
Step 13/16 : ENV SELF_SIGNED=$SELF_SIGNED
 ---> Using cache
 ---> fa5467ae20c8
Step 14/16 : ENV NO_DEFAULT=$NO_DEFAULT
 ---> Using cache
 ---> a1e25dc9605c
Step 15/16 : RUN /bin/bash /root/scripts/build-nginx.sh
 ---> Running in ddbcba4481b9
/root/scripts/build-nginx.sh: line 2: $'\r': command not found
/root/scripts/build-nginx.sh: line 3: syntax error near unexpected token `$'do\r''
'root/scripts/build-nginx.sh: line 3: `for conf in /etc/nginx/templates/*.conf; do
ERROR: Service 'nginx' failed to build: The command '/bin/sh -c /bin/bash /root/scripts/build-nginx.sh' returned a non-zero code: 2

Add PostGIS to the PostgreSQL image

PostGIS is in demand and should be added to the PostgreSQL image, maybe it could be disabled by default and enable via an environment variable in the docker-compose.yml?

Originally asked by @sign0 in #43

Node service exits immediately after fresh build following instructions on home page

I followed the instructions on the home page to try this repo out:

git clone https://github.com/Osedea/nodock.git
cp nodock/_examples/nginx/* . 
cd nodock/ && docker-compose up -d node nginx

The nginx node comes up fine but the node node fails immediately with the following error

    at Function.Module._resolveFilename (module.js:557:15)
    at Function.Module._load (module.js:484:25)
    at Function.Module.runMain (module.js:703:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:665:3

Am I missing or not understanding something here?

Project setup script

If we want to have the whole development of a node project doable from NoDock, we a way to init the project, maybe provide scaffolding?

Add Apache container

Have apache work as a dropdown replacement for nginx (VirtualHost configs, ssl, routing, etc.).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.