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.
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
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.
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
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.
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
List all volumes
root@localhost:~# docker volume ls
DRIVER VOLUME NAME
...
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
Create a new folder for your project and name it carefully (the name gets used in the life of the container). Create a file:
docker-compose.yaml
version: "3"
services:
db:
image: postgres:11-alpine
environment:
POSTGRES_DB: wiki
POSTGRES_PASSWORD: wikijsrocks
POSTGRES_USER: wikijs
logging:
driver: "none"
restart: unless-stopped
volumes:
- db-data:/var/lib/postgresql/data
wiki:
image: requarks/wiki:2
depends_on:
- db
environment:
DB_TYPE: postgres
DB_HOST: db
DB_PORT: 5432
DB_USER: wikijs
DB_PASS: wikijsrocks
DB_NAME: wiki
restart: unless-stopped
ports:
- "80:3000"
volumes:
db-data:
Watch out for indentation!
Pro tip, if you specify multiple services in one compose file, the common network will be automatically created.
$ docker-compose up
To bring everything down at once:
$ docker-compose down
To update images:
$ docker-compose pull
To access the PostgreSQL database inside docker:
root@localhost:~# docker exec -it root_db_1 /bin/bash
bash-5.1# psql -p 5432 -d wiki -U wikijs -h localhost