NodeBB 0.8.x and Docker, stand alone container desired

I've been working on building NodeBB in a docker container, and I'm working with the latest branch.

When I initially launch the container (docker run -it ... nodebb_image ) I get the command line options to configure the container, which is fine (although I'd like to automate this if possible). The second time I launch the container however (docker start nodebb, i.e. reuse the container) it does not detect that NodeBB has been set up and tries to run the command-line setup again. In order to finish launching the container, I have to docker attach nodebb and kill the setup script. After that, NodeBB starts up as expected.

I've noticed in the Dockerfile contains this stanza: CMD node app --setup && npm start which seems to me like it would run setup by default no matter what. Is that the expected behavior? It seems to me that Docker users would want to create a container that could be restarted any time without requiring any other interaction other than docker start <container>.

Is there an environment variable that can be set to tell NodeBB that it has been set up previously and to skip the setup or otherwise have? Or is there a list somewhere of all the docker run -e options that must/can be set up for a functioning instance?

Would pre-configuring NodeBB before building the docker container be a better and is this even an option?

Our work has taken us down the path of injecting a config.json file into the docker container. In spite of this, the container will still require the interactive configuration at runtime.

Also, it appears though that the npm package connect-redis isn't getting installed until the setup script is run, and if I attempt to circumvent the setup routine (i.e. with the config.json injected as stated above) the docker container startup will fail.

I've tried adding connect-redis to the package.json file, but this seems to have no effect.

I've noticed in the Dockerfile contains this stanza: CMD node app --setup && npm start which seems to me like it would run setup by default no matter what. Is that the expected behavior? It seems to me that Docker users would want to create a container that could be restarted any time without requiring any other interaction other than docker start <container>.

Quick explanation (prolly more behind it, very very tired right now though so I can't really remember):

By default the Docker image requires all environment variables to be specified because having to deal with data that isn't in the image itself can be a pain, so this keeps the image stateless.

node app --setup is always run before starting the image because any files this creates is deterministically based on the data passed to the -e arguments, so it can just be thrown away and you don't need to deal with moving it around between different machines in HA scenarios.

You could also address all this by simply putting the environment variables in the Dockerfile when building it, but you can't really use the public Docker Hub for this as it'd post your DB info - and also the session secret, which you should specify if loadbalancing across multiple containers.

I've tried adding connect-redis to the package.json file, but this seems to have no effect.

Is there a way around this?

npm install runs when you build the image (thus version-locking all dependencies without something like npm shrinkwrap), anything you do afterwards just behaves normally - i.e. adding things to the package.json using a text editor (or sed, etc. you get the idea) doesn't automagically install them.

Would pre-configuring NodeBB before building the docker container be a better and is this even an option?

It's definitely possible! You could base your image on our image and specify all the configuration stuffs using ENV, use a RUN directive to run node app --setup at build-time and optionally add a CMD directive that's just npm start. (the CMD is the default command ran if you start the container without supplying any, also your CMD would override ours )

Good luck, hope this helps a bit and sorry if you knew more than I cautiously assumed you might when writing this post - well, at least that'd make it also useful to any stray Googlers out there looking for help...

though I'd be careful pulling the image from the Docker Hub at all right now, since nothing is tagged right now, so you're pretty much stuck always pulling the latest master or whatever commit the buildid you've specified corresponds to.

@a_5mith
Yes I have already checked it. I have found a docker image created by @nopz, this one is up-to-date. But the official docker image in not! Maybe you (nodebb) should give access to a dockerfile to allow anyone to build a nodebb docker image. EDIT I found the dockerfile, and the problem about this outdated version here. It's outdated because the dockerfile build the image with the v0.5.x version :
FROM centos:centos7
MAINTAINER NodeBB Docker Team <docker-devs@nodebb.org>
# install main packages:
RUN yum -y update ; yum clean all
RUN yum -y install epel-release tar ; yum clean all
RUN yum -y install wget ; yum clean all
RUN yum -y groupinstall "Development Tools"
RUN yum -y install nodejs git ImageMagick npm
RUN yum -y install openssl openssl-devel
# clone nodebb and install it
RUN cd /opt ; git clone -b v0.5.x https://github.com/NodeBB/NodeBB nodebb
RUN cd /opt/nodebb ; npm install
# Create a nodebb volume
VOLUME /opt/nodebb
# Define a working directory
WORKDIR /opt/nodebb
# Expose ports
EXPOSE 80
EXPOSE 443
EXPOSE 4567
CMD [ "node", "app.js" ]
You should (NodeBB) update this dockerfile !
End of the EDIT
Now, with the nopz/nodebb image I just had a problem about plugin persistence. But the first installation is so much easier and automatic with just one docker.
Thanks for your answer by the way