373 words
2 minutes
YOURLS Link Shortener with Docker

YOURLS Link Shortener with Docker#

Set up YOURLS link shortener with Docker for a quick and simple way to manage your links.

Docker Compose#

Create a folder named “yourls”:

mkdir yourls
cd yourls

Create docker-compose.yml:

nano docker-compose.yml

Edit compose.yml:

version: '3.1'

services:

  yourls:
    image: yourls
    restart: always
    ports:
      - 10082:80
    environment:
      YOURLS_DB_PASS: ****
      YOURLS_SITE: https://go.example.com
      YOURLS_USER: juyoung
      YOURLS_PASS: ****
    volumes:
      - ./plugins:/var/www/html/user/plugins
      - ./root:/var/www/html

  mysql:
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ****
      MYSQL_DATABASE: yourls
    volumes:
      - ./mysql-data:/var/lib/mysql
  1. Change YOURLS_SITE.
  2. Use the same password for both YOURLS_DB_PASS and MYSQL_ROOT_PASSWORD.
  3. Set YOURLS_USER and use a unique password for YOURLS_PASS. These will be your username and password for logging into YOURLS dashboard.

If your password has a $ symbol, write $$ instead. This is because Docker thinks $ is a variable name and $$ tells it to use a normal $.

(Retrieved from YOURLS Docker Hub on January 23, 2025)

Caddy#

Install Caddy:

apt install caddy
sudo systemctl enable caddy

Open Caddyfile:

nano /etc/caddy/Caddyfile

Edit Caddyfile:

example.com {
  # You can use a different name instead of "/go." Change "YOURLS_SITE:" in docker-compose.yml file. 
  route /go* {
    uri strip_prefix /go
    redir https://go.{host}{uri}
  }
}

# To use a different port, change the "ports:" section in your docker-compose.yml file.
go.example.com {
  reverse_proxy localhost:10082
  encode zstd gzip
}

Restart Caddy:

sudo systemctl restart caddy

Go to YOURLS dashboard at https://go.example.com/admin or at https://example.com/go/admin if you prefer using a subpath. Don’t forget the “/admin” part.

YOURLS Plugins#

YOURLS comes with minimal features, but you may want to install plugins for additional functionality. You can find a list of available plugins at YOURLS Awesome Plugins (https://github.com/YOURLS/awesome).

To install a plugin, create a folder named after the plugin inside the “plugins” folder.

Run ls to view the “plugins” folder and go into it:

ls
cd plugins

Create folder named after the plugin:

mkdir <plugin-name>

Place plugin files inside this folder, then go to Plugins administration page to activate the plugin.

Recommended Plugins

YOURLS Link Shortener with Docker
https://blog.juyoun.gg/posts/en/2025/02/22/
Author
Jay
Published at
2025-02-22
License
CC BY