NodeBB with Docker full chain ( nginx, redis, mongodb )

Tutorials
  • I would like to introduce what I have done with a NodeBB and a docker.

    This docker chain of Nginx, NodeBB, Redis, MongoDB(!!) is based on Alpine Linux and docker-compose.
    This design is mainly for developments and small standalone service rather than large distributable/scalable service.

    A Major Difference from other many(?) docker implementations is that I don't embed source and config files into images but just mount most of files on a host directory to containers even include NodeBB source and node_modules. There are pros and cons. I'll explain them briefly and we could discuss them.

    UPDATE

    A MongoDB is added as a default DB !!!
    And redis is intened to be used for websock blabla, but I'm not sure it's properly working.

    What I know actually, no errors, no warnings and I can see both of mongo and redis at admin web UI.

    If anybody would try this docker chain, please let me know results.

    !!! WARNING !!!
    I haven't checked yet how mongod and redis-server manage SIGTERM which docker send.
    This means that in worst case one can loose data !
    Does any body know about this?

    • mongod and redis-serverhas been checked. Safe with docker stop but not with docker kill

    Installation

    • This chain consists of 4 docker containers each of NodeBB, Redis, MongoDB, Nginx.
    • I don't provide compiled images but 10 mins will be more than enough to build them by yourself with this instructions. 🙂
    • You will get error from a nginx docker if you already have any web server with port 80. I'll explain solutions after lines.
    git clone https://github.com/qgp9/nodebb-docker-dev.git nodebb-docker-dev
    cd nodebb-docker-dev
    git clone -b v1.x.x https://github.com/NodeBB/NodeBB.git nodebb
    ./bin/com-nodebb npm install
    ./bin/com-nodebb npm install socket.io-redis connect
    ./bin/com-nodebb npm setup
    ./bin/utils jq -M -s add nodebb/config.json conf/example/redis.josn > tmp.json && mv tmp.json nodebb/config.json
    ./bin/docker-compose up 
    
    • DB: mongo , DB address: mongodb , DB user: admin , no DB password
    • If you have a web server already, you have two options
      1. Remove a nginx from docker-compose.xml , connect a port 4567 of NodeBB to host, and you may know how you can connect from your webserver to http://127.0.0.1:4567 . Here is a example docker-compose.xml
      2. change a external port of a nginx docker ( example is 8080 ) and connect from your web server to http://127.0.0.1:8080. Here is a example docker-compose.xml

    Command line Settings, Upgrade, npm and so on

    When you want to do ./nodebb setup or ./nodebb upgrade or npm install on your nodebb, don't do it on Host directory. You have a helper script, do next.

    ./bin/com-nodebb ./nodebb setup
    ./bin/com-nodebb ./nodebb upgrade
    ./bin/com-nodebb npm install <package>
    

    Also you can open bash and do whatever you want

    ./bin/com-nodebb bash
    
    • But to edit/add/delete files, git pull, you can do it on the host directory ( or with docker, doesn't matter )

    Structure

    nodebb-docker-dev
    ├── bin   
    │   ├── com-nodebb      # Helper to control NodeBB docker
    │   └── docker-compose  # Docker version of docker-compose for portability
    ├── conf                # All Dockerfile and configuration.
    │   ├── nginx
    │   │   ├── Dockerfile
    │   │   └── nginx.conf
    │   ├── nodebb-dev
    │   │   └── Dockerfile
    │   └── redis
    │       ├── Dockerfile
    │       └── redis.conf
    ├── data
    │   ├── nginx
    │   │   └── logs         # nginx, site logs
    │   ├── nodebb           # Empty. reserved for future plans.
    │   └── redis            # dump.rgb ( db data ) , redis.log ( log file ) 
    ├── docker-compose.yml
    └── nodebb               # NodeBB source will be here 
    
    • All configuration, data( log file ), NodeBB codes are mounted to dockers ( not copied ). So you can just edit them on a host directory.
    • All configurations are in a conf directory. All data files genereated by nginx, redis are in a data directory.
      • Exceptionally config.json and a logfile of NodeBB are in nodebb directory for easy management.
    • This desigin is aimed to archive easy and best development/management system for small standalone service.
      • Every improtant files are just under a main directory on a host and dockers act just like applications,
      • so you can remove/rebuild docker containers/images freely without any effect to data.
      • Also you can easily migrate this chain to new server. What you need is just copy the main directory to new server and rebuild dockers.
      • But large distributing/scaling can meet some side effects.

    Project Name

    When you build a system by ./bin/docker-compose up, you will see a wired long name of images/container like nodebbdockerdev_nginx by docker images or docker ps -a. This is because docker-compose use a directory name as a project nam.
    To get a short/readable name , you have recommontable 2 options.

    1. Change the directory name
    2. Shell variables ( RECOMMENDED but easilly one can make mistakes. smartcd can help )
      • export COMPOSE_PROJECT_NAME=qgp9
      • or you can embed this variable to ./bin/com-nodebb and ./bin/docker-compose
        Then you will see qgp9_nginx.

    And

    More details will be .. updated at the github repo soon.

    Any questions/comments/ideas/criticizing/WOW/BOO~ ?

  • I could successfully migrate my old nodebb system to a dockrized chain.
    It was ubuntu based and I got some troubles with nginx configurations and ssl keys from letsencrypt, but in the end every things are fine now without large modifications from my orignal github repo.

    If some body needs/wants, I'll post it and also update the github repo. 🙂

  • UPDATE

    A MongoDB is added as a default DB !!!
    And redis is intened to be used for websock blabla, but I'm not sure it's properly working.

    What I know actually, no errors, no warnings and I can see both of mongo and redis at admin web UI.

    If anybody would try this docker chain, please let me know results.

  • Hi! I tried installing your docker container. After executing the instruction "./bin/docker-compose up" I put the nodebb setting in my browser, but then I got one of these errors in the terminal where I ran the docker-container:
    error: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    or
    error: NodeBB could not connect to your Mongo database. Mongo returned the following error: connect ECONNREFUSED 127.0.0.1:27017

    One of full logs:
    nodebb_1  | Welcome to NodeBB!
    nodebb_1  | 
    nodebb_1  | This looks like a new installation, so you'll have to answer a few questions about your environment before we can proceed.
    nodebb_1  | Press enter to accept the default setting (shown in brackets).
    nodebb_1  | 
    nodebb_1  | 26/5 16:52 [50] - info: Now configuring redis database:
    nodebb_1  | Configuration Saved OK
    nodebb_1  | Populating database with default configs, if not already set...
    nodebb_1  | 26/5 16:52 [50] - error: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    nodebb_1  |     at Object.exports._errnoException (util.js:870:11)
    nodebb_1  |     at exports._exceptionWithHostPort (util.js:893:20)
    nodebb_1  |     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
    

    or

    nodebb_1  | Welcome to NodeBB!
    nodebb_1  | 
    nodebb_1  | This looks like a new installation, so you'll have to answer a few questions about your environment before we can proceed.
    nodebb_1  | Press enter to accept the default setting (shown in brackets).
    nodebb_1  | 
    nodebb_1  | 26/5 19:27 [32] - info: Now configuring mongo database:
    nodebb_1  | Configuration Saved OK
    nodebb_1  | 26/5 19:27 [32] - error: NodeBB could not connect to your Mongo database. Mongo returned the following error: connect ECONNREFUSED 127.0.0.1:27017
    nodebb_1  | 26/5 19:27 [32] - warn: NodeBB Setup Aborted.
    nodebb_1  |  Error: connect ECONNREFUSED 127.0.0.1:27017
    nodebb_1  |     at Object.exports._errnoException (util.js:870:11)
    nodebb_1  |     at exports._exceptionWithHostPort (util.js:893:20)
    nodebb_1  |     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
    
  • I tried you repo, but unfortunately the Mongo container fails:

    mongodb_1  | Error relocating /usr/bin/mongod: _ZNK5boost16re_detail_10600031cpp_regex_traits_implementationIcE17transform_primaryEPKcS4_: symbol not found
    
    mongodb_1  | Error relocating /usr/bin/mongod: _ZNK5boost16re_detail_10600031cpp_regex_traits_implementationIcE9transformEPKcS4_: symbol not found
    
    nodebbdockerdev_mongodb_1 exited with code 127
    

    Searching StackOverflow it seems this is an issue with Mongo on Alpine...

    (I using Docker beta for MacOS, but I don't think this is the issue)

  • When Running the first config command it failes like:

    $ ./bin/com-nodebb npm install

    ERROR: oci runtime error: container_linux.go:247: starting container process caused "exec: \"npm\": executable file not found in $PATH"
    

    Is that normal ?

  • @qgp9 Any idea about that ^^

  • npm either isn't installed or is installed incorrectly.

  • I try to this docker chain, and got some error after exec sudo ./bin/com-nodebb npm install:

    Successfully built ee060087bd12
    Successfully tagged nodebbdockerdev_nodebb:latest
    npm WARN saveError ENOENT: no such file or directory, open '/opt/nodebb/package.json'
    npm notice created a lockfile as package-lock.json. You should commit this file.
    npm WARN enoent ENOENT: no such file or directory, open '/opt/nodebb/package.json'
    npm WARN nodebb No description
    npm WARN nodebb No repository field.
    npm WARN nodebb No README data
    npm WARN nodebb No license field.

    and idea?

  • Don't use sudo. What tutorial or guide are you using?

  • @pitaj just follow you guide, if without sudo, I may not have permission to exec this command , you had suggest?

  • @alphagao link me whatever guide you're using. If you don't know what to do, use this guide:


Suggested Topics


  • 1 Votes
    14 Posts
    1k Views

    Yeah @kurulumu-Net you can change port in config.json in one of the NodeBBs and change to the same port in the proxy-pass part of the corresponding nginx config.

    Default port is 4567, one will need to be changed.

  • 4 Votes
    9 Posts
    2k Views

    @ᴅᴀʀᴛʜ-ᴠᴀᴅᴇʀ It probably crashes because of the plugins you installed and nodebb can't find them (nodebb-theme-oxide in particular)

    I suggest you backup the redis database by copying the /data folder somewhere, then delete the contents of the original folder and also remove the config.json volume.

    Erase and restart redis and nodebb container (It should be like a fresh install) then installs the plugins and themes listed in the log file (nodebb-plugin-teamspeak-verify, nodebb-widget-search-bar, nodebb-theme-oxide, etc)

    When all plugins are installed and enabled, stop the nodebb container and restore the /data redis database with your backup, and remap config.json volume and I think it should be up.

    Next time you want to upgrade, disable all plugins before restarting the container with the new image.

  • 0 Votes
    5 Posts
    2k Views

    Problem solved, for the record I have added all file on my GitHub: https://github.com/LM1LC3N7/Dockerfiles/blob/master/nodebb/README.md

  • 0 Votes
    8 Posts
    4k Views

    @flex said:

    Do you think that it's possible to don't use yours and replace it by my reverse proxy ?

    HI, If you meant that one use a niginx which is installed on a host instead of a dockerized nginx which is dedicated for NodeBB, then it's totally possible, yes 🙂

    I just put some ideas and matters

    One can remove a dockerized nginx easily by just a modifying(removing) of nginx part from docker-compose.yml. Really, that's just it. ( This is a full chain, but if one doesn't need/want a full chain then.. 🙂 ) One can use a dockerized nginx as a prime web server instead a host installed web server and can serve subomains or what ever with other docker or directory Actually this doesn't happen yet, but nginx can serve static files for NodeBB efficiently and you know, nginx is extremely small. So I'd rather proxy from a host installed nginx to the nodebb dedicated nginx docker ( In this case one needs to change a line 80:80 with 8080:80 or <any port>:80 in docker-compose.yml )

    But, if anybody wants to get an easier way and less steps, then your idea will be also a good option.

  • 0 Votes
    4 Posts
    2k Views

    Thanks a lot! It works 😄