NodeBB 0.8.x and Docker, stand alone container desired



  • Hello,

    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>.

    I've also read the General-Purpose Dockerfile conversation (here: https://github.com/NodeBB/NodeBB/pull/3160) and tried to apply some of that.

    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?

    Thanks,

    Michael



  • 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.

    Is there a way around this?



  • @MichaelM said:

    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.

    @MichaelM said:

    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.

    @MichaelM said:

    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.



  • @Xiph Thank you so much for the reply!

    We're not actually pulling images from Docker Hub, as the default image out there seems to just pull an 0.5 branch. We're actually building the image from source using the Dockerfile that is included.

    The info you included will be super helpful in getting this going the way we want. We will not be posting these images publicly, for the exact reasons you mentioned above (i.e. secret).

    I'll probably be back with more questions though. 😃



  • This post is deleted!

Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.