Docker includes a tool called Docker Composethat helps you create multi container applications.We’ll use it to create two containers that will run nodebb and mongodb (named as such respectively). We’ll set nodebb to depend on mongodb container so it will wait for mongodb to run first. This whole docker-compose file lets us write docker run arguments in a config file so we can easily tweak stuff.
Benefits of Docker Compose
Single host deployment – This means you can run everything on a single piece of hardware
Quick and easy configuration – Due to YAML scripts
High productivity – Docker Compose reduces the time it takes to perform tasks
Security – All the containers are isolated from each other, reducing the threat landscape
How to setup Nodebb in a docker container through docker-compose
This works in tandom with a .env file. The env file will hold values of all the variables used here. Please replace them with the name of your website/domain and usernames and password values. This setup will create a user, database and password on mongo db automatically. I like to use bitnami images because they provide comprehensive documentation and maintain there images. You can read their docs here https://github.com/bitnami/bitnami-docker-mongodb.
Example of .env file
#Nodebb specific variables
#Bitnami MongoDB specific variables
As we are using Bitnami’s public images for Mongodb we need to look at their docs for any mongodb related issues. In recent versions they are defaulting to non-root containers for better security so it is better to setup without the root user. What that means is that your db volume folder needs to give access to 1001 user.
You can remove following from the docker-compose file and give permissions to your shared volume and then try again.