CREATIVE CHAOS

Instant Wiki.js with Docker

PUBLISHED ON 07/02/2021 — EDITED ON 07/02/2021 — SYSOPS

Intro

This could maybe be a little intro to docker, or not.

In this crazy short tutorial, we will see how to deploy a working Wiki.js instance in 10 commands with Docker.

Please note, this setup is useful for testing purposes. To make it to production, we should really look into Linux hardening and configure the server properly. The recommended database for Wiki.js is Postgres and support for other backends will be dropped in the future, they also specificly state that SQlite is not meant for production use.

Preparing the server

Create a new node/server with Debian 10 on your favourite provider.

Log in the server as root.

$ ssh root@wonderfulnewinstance -i throw-a-key-for-a-good-measure

10 commands until deployment

Execute:

root@localhost:~# apt-get update
root@localhost:~# apt-get upgrade
root@localhost:~# apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
root@localhost:~# curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
root@localhost:~# apt-key fingerprint 0EBFCD88
root@localhost:~# add-apt-repository    "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"
root@localhost:~# apt-get update
root@localhost:~# apt-get install docker-ce docker-ce-cli containerd.io
root@localhost:~# docker pull requarks/wiki
root@localhost:~# docker run -d -p 8080:3000 --name wiki --restart unless-stopped -e "DB_TYPE=sqlite" requarks/wiki

BAM, done!

Visit http://IP-OF-INSTANCE:8080 and configure your shiny new wiki.

docker run command explained

So to convert the image to container and run it, we used:

root@localhost:~# docker run -d -p 8080:3000 --name wiki --restart unless-stopped -e "DB_TYPE=sqlite" requarks/wiki

-d run container detached

-p 8080:3000 bind port 8080 on host to port 3000 on container

--name wiki name the container, so we can easier manage it

--restart unless-stopped keep the container running until we say so

-e "DB_TYPE=sqlite" set environment variable, in our case defining which backend database should wikijs use

requarks/wiki image name

Random docker commands

Other docker commands one can find useful.

List images on your system:

root@localhost:~# docker images
REPOSITORY      TAG       IMAGE ID       CREATED        SIZE
requarks/wiki   latest    f439bc73d690   3 months ago   429MB

List running containers:

root@localhost:~# docker ps
CONTAINER ID   IMAGE           COMMAND                  CREATED      STATUS      PORTS                              NAMES
5606d1a1c78b   requarks/wiki   "docker-entrypoint.s…"   2 days ago   Up 2 days   3443/tcp, 0.0.0.0:8080->3000/tcp   wiki

List all containers

root@localhost:~# docker ps -a
CONTAINER ID   IMAGE           COMMAND                  CREATED      STATUS                  PORTS                              NAMES
5606d1a1c78b   requarks/wiki   "docker-entrypoint.s…"   2 days ago   Up 2 days               3443/tcp, 0.0.0.0:8080->3000/tcp   wiki
7ad0c31fcfce   requarks/wiki   "docker-entrypoint.s…"   2 days ago   Exited (1) 2 days ago                                      amazing_black

Remove a container:

root@localhost:~# docker rm amazing_black
amazing_black

View logs of a container:

root@localhost:~# docker logs wiki
Loading configuration from /wiki/config.yml... OK
2021-02-05T09:48:12.885Z [MASTER] info: =======================================
2021-02-05T09:48:12.887Z [MASTER] info: = Wiki.js 2.5.170 =====================
2021-02-05T09:48:12.888Z [MASTER] info: =======================================
2021-02-05T09:48:12.888Z [MASTER] info: Initializing...

Get a shell in container:

root@localhost:~# docker exec -it wiki /bin/bash
bash-5.0$

In contrast to run that works with images, after you use it to create a container, you can work with it via:

docker start wiki
docker stop wiki

Final words

Do not forget to nuke the instance from the orbit, as the safety is questionable. Also, if you have created the instance on some popular cloud provider, deleting the instance prevents the billing.

docker compose

docker run -d -p 8080:3000 --name wiki --restart unless-stopped -e "DB_TYPE=sqlite" requarks/wiki

wikijs-docker-compose.yaml

version: '3'
    services:
        wiki:
            image: requarks/wiki
            ports: 
             - 8080:3000
            environment:
             - DB_TYPE=sqlite

Watch out for indentation!

Pro tip, if you specify multiple services in one compose file, the common network will be automatically created.

$ docker-compose -f wikijs-docker-compose.yaml up

To bring everything down at once:

$ docker-compose -f wikijs-docker-compose.yaml down

See Also