Self-hosted Wallabag using Docker

To keep track of articles I want to read, my tool of choice was wallabag. This tool offers a nice way of saving an article’s content and providing a custom view to read those “offline”. And by “offline” I mean online, but on my wallabag instance and not on the author’s site. Another big advantage is to avoid annoying advertisement on the article’s homepage. I’m using it as a self-hosted alternative to Pocket.

On Docker Hub, a comprehensive documentation is provided, explaining how to install and configure wallabag running in a Docker container. Like my other web services running in Docker, I wanted to access wallabag via an encrypted HTTPS connection using Traefik as a reverse proxy.

My running instance of wallabag consists of three Docker container specified as services in a docker-compose.yml file:

  1. Wallabag
  2. SMTP
  3. Web server

1. Wallabag

Based on wallabag’s official Docker image I changed only two environment variables (line 6 and 7) and added two volumes (line 13 and 14). Line 14 enables saving wallabag’s SQLite database outside the container.

[...]
services:
  wallabag:
  image: wallabag/wallabag
  environment:
    - SYMFONY__ENV__MAILER_HOST=smtp
    - SYMFONY__ENV__DOMAIN_NAME=https://wallabag.domain.net
  links:
    - smtp
  depends_on:
    - smtp
  volumes:
    - /path/to/wallabag/images:/var/www/wallabag/web/assets/images
    - /path/to/wallabag/data/db:/var/www/wallabag/data/db
  labels:
    - traefik.enable=false

I chose SMTP to send mails from wallabag and therefore needed an SMTP service. It is by far not the best option, but it works. And it is just for sending a single mail per registered user, so in my case just one mail.

2. SMTP

For wallabag’s initial registration process, a mail containing an opt-in link needs to be sent. To be able to send messages, I added a second Docker container running an SMTP server. This container is only reachable from within Docker’s private network. So it is not available for the outside world.

[...]
services:
[...]
smtp:
  image: namshi/smtp
  labels:
    - traefik.enable=false
[...]

This sets up a dedicated SMTP server. It is not the best idea because it is not too hard getting blacklisted. For example mailbox.org, my mail provider, is filtering my mails and Gmail is not. But I’m just sending a single registration mail, which justifies this solution in my eyes.

3. Web server

Only the web server, that is required to run wallabag, is known to Traefik but still only reachable from Docker itself.

[...]
services:
[...]
web:
  image: nginx
  volumes:
    - ./nginx.conf:/etc/nginx/nginx.conf:ro
  links:
    - wallabag
  environment:
    - VIRTUAL_PORT=80
  labels:
    - traefik.enable=true
    - traefik.backend=wallabag
    - traefik.frontend.rule=Host:sub.domain.net
    - traefik.docker.network=proxy

As you can see in line 7, I’m providing a read-only nginx configuration file. I have to admit that this configuration file results from a try-and-error session. The problem I had to tackle was to let wallabag work together with Traefik as a reverse proxy and its forwarded HTTP requests.

user www-data;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  server {
    listen 80;

    location / {
      proxy_pass http://wallabag;
      proxy_set_header X-Forwarded-Host $server_name;
      proxy_set_header X-Forwarded-Proto https;
      proxy_set_header X-Forwarded-For $remote_addr;
    }
  }
}

Summary

Getting wallabag to run in a Docker container was not that easy. The first problem was to find a working nginx configuration. I am no web server expert and had almost no experience with nginx. That’s why it took quite some time to find and set the correct parameters.

As soon as wallabag was up and running, I was quite happy and started saving articles. At this time, I had a MySQL container running and assumed to have it connected to wallabag. But that was not the case, as I noticed later on. All my data was gone, user account as well as saved articles. So I started again, but was not able to have a proper connection. That’s why I am now just saving wallabag’s default SQLite database outside the container.

Leave a Reply

Your email address will not be published. Required fields are marked *