Skip to content

Latest commit

 

History

History
182 lines (131 loc) · 7.45 KB

Docker.md

File metadata and controls

182 lines (131 loc) · 7.45 KB

Stringer on Docker

Production ready setup using docker-compose

Download docker-compose.yml and, in the same folder, run:

touch .env && docker compose up -d

Stringer only accepts HTTPS by default, so put a reverse proxy with an SSL certificate in front of it (see the examples below) and visit it there. Stringer listens on port 8080 and only accepts connections from the same machine, so the proxy needs to run there too. If your proxy runs in its own container, add it to stringer-network and point it at stringer:8080 instead.

To try it out locally without a proxy, add ENFORCE_SSL=false to .env before starting it, then give it a minute and visit localhost:8080. If your browser already visited it while HTTPS was enforced, it may keep switching to https://. Clear the site's data in your browser to fix that.

On its first boot Stringer writes its secret keys to .env. Keep this file, and back it up along with your database: without the keys, Stringer can't read the encrypted data it has stored.

You can also set other options in .env, such as FETCH_FEEDS_CRON and CLEANUP_CRON.

The database uses a default password, stringer. That's fine as long as Postgres is only reachable from the Stringer container, which is how docker-compose.yml sets it up. If you change it to publish the Postgres port, set your own password first by adding POSTGRES_PASSWORD=... to .env before the first docker compose up.

Production ready manual setup

The following steps can be used to setup Stringer on Docker, using a Postgres database also running on Docker.

  1. Setup a Docker network so the two containers we're going to create can communicate:
docker network create --driver bridge stringer-network
  1. Setup a Postgres Docker container:
docker run --detach \
    --name stringer-postgres \
    --restart always \
    --volume /srv/stringer/data:/var/lib/postgresql \
    --net stringer-network \
    -e POSTGRES_PASSWORD=myPassword \
    -e POSTGRES_DB=stringer \
    postgres:18-alpine
  1. Run the Stringer Docker image:
docker run --detach \
    --name stringer \
    --net stringer-network \
    --restart always \
    -e PORT=8080 \
    -e DATABASE_URL=postgres://postgres:myPassword@stringer-postgres/stringer \
    -e SECRET_KEY_BASE=$(openssl rand -hex 64) \
    -e ENCRYPTION_PRIMARY_KEY=$(openssl rand -hex 64) \
    -e ENCRYPTION_DETERMINISTIC_KEY=$(openssl rand -hex 64) \
    -e ENCRYPTION_KEY_DERIVATION_SALT=$(openssl rand -hex 64) \
    -e FETCH_FEEDS_CRON="*/5 * * * *" \ # optional
    -e CLEANUP_CRON="0 0 * * *" \ # optional
    -p 127.0.0.1:8080:8080 \
    stringerrss/stringer:latest

That's it! You now have a fully working Stringer instance up and running!

Upgrading Postgres

The setup above uses Postgres 18. Older setups used Postgres 16 or, before 2024, Postgres 9.5. These steps work from any of them. Two things changed:

  • A Postgres major version cannot read data files written by an older one.
  • The official 18+ image expects a single mount at /var/lib/postgresql (not /var/lib/postgresql/data) and stores the database in a version-named subdirectory inside it.

If you start the 18 image against an existing older data directory it refuses to start and prints an explanation, so nothing is lost. But you do need to migrate by hand. Stringer databases are small, so the simplest route is to dump and restore.

  1. With the old container still running, dump everything:
docker compose exec stringer-postgres sh -c 'pg_dumpall -U "$POSTGRES_USER"' > stringer-backup.sql
  1. Stop the stack and move the old data directory aside:
docker compose down
sudo mv /srv/stringer/data /srv/stringer/data-old

If you're coming from Postgres 9.5, your data is in ~/stringer instead. The new setup doesn't use that folder, so you can skip the move.

  1. Update docker-compose.yml (or re-download it): change the image to postgres:18-alpine and the volume to /srv/stringer/data:/var/lib/postgresql.

  2. Start only the database and wait for it to accept connections:

docker compose up -d stringer-postgres
until docker compose exec stringer-postgres pg_isready -h localhost; do sleep 1; done
  1. Restore the dump. Errors saying a role or database "already exists" are expected and harmless, because the fresh container already created them:
docker compose exec -T stringer-postgres sh -c 'psql -U "$POSTGRES_USER" -d postgres' < stringer-backup.sql
  1. Set the database password again. The restore copies over the old password, and if it came from Postgres 13 or older it's saved in a format Postgres 18 rejects. Stringer then can't connect, and Rails reports "Database not found". Running this is harmless if your password was already fine:
docker compose exec stringer-postgres sh -c 'psql -U "$POSTGRES_USER" -d postgres -c "ALTER ROLE \"$POSTGRES_USER\" PASSWORD '"'"'$POSTGRES_PASSWORD'"'"'"'
  1. Start the rest of the stack and check that your feeds and stories are there:
docker compose up -d
  1. Once you are happy, delete the old data directory (/srv/stringer/data-old or ~/stringer) and stringer-backup.sql.

If you used the manual setup instead of docker-compose, run the same commands with docker exec stringer-postgres in place of docker compose exec stringer-postgres, and recreate the Postgres container with the new image and volume path in step 3.

Reverse proxy

For production use, put a reverse proxy with an SSL certificate in front of Stringer. The proxy handles HTTPS and passes requests to Stringer over plain HTTP.

Caddy (https://caddyserver.com/):

stringer.example.org {
	proxy / localhost:8080 {
      transparent
	}
}

Nginx (https://nginx.org/):

server {
        listen      [::]:80;
        listen      80;
        server_name stringer.example.org;
        access_log  /var/log/nginx/stringer.example.org-access.log;
        error_log   /var/log/nginx/stringer.example.org-error.log;

        return 301 https://$host:443$request_uri;
}

server {
        server_name stringer.example.org;

        access_log  /var/log/nginx/stringer.example.org-access.log;
        error_log   /var/log/nginx/stringer.example.org-error.log;

        listen      [::]:443 ssl http2;
        listen      443 ssl http2;

        # see https://mozilla.github.io/server-side-tls/ssl-config-generator/
        # for ssl best practices.
        # Or use Letsencrypt, with certbot.
        ssl_certificate ssl/fullchain.pem;;
        ssl_certificate_key ssl/privatekey.pem;
		

        location    / {
                gzip on;
                gzip_min_length  1100;
                gzip_buffers  4 32k;
                gzip_types    text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml  application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
                gzip_vary on;
                gzip_comp_level  6;

                proxy_pass  http://localhost:8080;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header X-Forwarded-Port $server_port;
                proxy_set_header X-Request-Start $msec;
        }
}