Deploy Your Own Wiki With WikiJS and Docker
I am looking into finding a decent open source wiki. I spent ages trying to get WikiJS up and running to evaluate it. Unfortunately, I don't think it's suitable for me, but wanted to post this to save other people the pain I had to go through in order to figure out how to get it set up. Perhaps one day the system will be improved to make it worthwhile.
The first thing we need to do is create a configuration file for our wiki. Use the following commands to open up the vim text editor in the relevant place:
mkdir -p $HOME/volumes/wiki cd $HOME/volumes/wiki wget https://raw.githubusercontent.com/Requarks/wiki/master/config.sample.yml mv config.sample.yml config.yml
For security, we need to change the session secret to something random. The script below will do this for you.
SEARCH="sessionSecret: 1234567890abcdefghijklmnopqrstuvxyz" REPLACE="sessionSecret: `openssl rand -base64 32`" FILEPATH="$HOME/volumes/wiki/config.yml" sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
As we will be using a container for our Mongo DB, we also need to change the database parameter in the config:
SEARCH="mongodb://localhost:27017/wiki" REPLACE="mongodb://wikidb:27017/wiki" FILEPATH="$HOME/volumes/wiki/config.yml" sed -i "s;$SEARCH;$REPLACE;" $FILEPATH
Setting Up Git
The wiki needs to connect to a git repository in order to be able to version control the wiki. As I intend to store sensitive information on the wiki and only have it accessible on a company intranet, it would defeat the purpose if I had it posting everything to a public Github repo. Instead, I am going to set it up with a repository in my private Gitlab server. I created a new account on my Gitlab server using a Gmail alias, then generated an ssh-key on the server without a passphrase and set that up for the wikijs user in Gitlab before then creating a repository for the wiki. Thus the wikijs server will have a key that can only access the one repository in Gitlab.
To copy the private SSH key to where we will need it for a volume mount, use:
cp $HOME/.ssh/id_rsa $HOME/volumes/wiki/git-ssh-key.pem
Review Git Config
After having set up your git repository, review the Git connection Info in your configuration file and update it accordingly. I have pasted mine below for reference:
# --------------------------------------------------------------------- # Git Connection Info # --------------------------------------------------------------------- git: url: firstname.lastname@example.org:wikijs/wikijs.git branch: master auth: # Type: basic or ssh type: ssh # Only for Basic authentication: username: wikijs password: myRandomPassword # Only for SSH authentication: privateKey: /etc/wiki/keys/git.pem #sslVerify: true # Default email to use as commit author serverEmail: email@example.com # Whether to use user email as author in commits showUserEmail: false
Deploy With Docker Compose
Install docker-compose if you haven't already.
Copy/paste the following
docker-compose.yml file to your server.
version: '3' services: wikidb: image: mongo:3 expose: - '27017' command: '--smallfiles --bind_ip ::,0.0.0.0' environment: - 'MONGO_LOG_DIR=/dev/null' volumes: - $HOME/volumes/mongo/db:/data/db wikijs: image: 'requarks/wiki:latest' links: - wikidb depends_on: - wikidb ports: - '80:80' environment: WIKI_ADMIN_EMAIL: firstname.lastname@example.org volumes: - $HOME/volumes/wiki/config.yml:/var/wiki/config.yml - $HOME/volumes/wiki/git-ssh-key.pem:/etc/wiki/keys/git.pem
email@example.com to your email address.
Now spin up your wiki and mongo containers, with the appropriate volumes by running:
Now navigate to your server's IP address or domain and you should see the screen below:
Login with the
WIKI_ADMIN_EMAIL you specified in the docker-compose.yml file, and use the password admin123.
You should then see the following page:
When I clicked on Create Home Page I was greeted with the following:
I couldn't figure out how to save, and gave up at this point because the whole thing looks butt ugly and I could have probably developed something better suited to my needs in less time than it took to set this thing up.
If you experience issues, the best thing to do is to enter the wiki container, and then go into the
/logs directory and view the error logs using
Alternatively, you could alter your docker-compose.yml file so that the
/logs folder is a volume so that you can access the logs from the host.