Install YOURLS Inside Docker Container in Linux

Install YOURLS Inside Docker Container in Linux

YOURLS is a URL shortening service that can be installed on the own server. YOURLS is an open-source project that released under the MIT license.

This tutorial explains how to install YOURLS inside a Docker container in the Linux. Commands have been tested on Ubuntu.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

You also need to have a running MySQL container. Instructions can be found in the post.

Install YOURLS

Before starting, create yourls database:

docker exec -it mysql mysql -u root -p -e "CREATE DATABASE yourls"
  • Host network

Run the following command to create a container for YOURLS that uses host network:

docker run -d --name=yourls --restart=always --network=host \
    -e YOURLS_SITE=http://192.168.0.252 \
    -e YOURLS_USER=admin \
    -e YOURLS_PASS=pwd123 \
    -e YOURLS_DB_USER=root \
    -e YOURLS_DB_PASS=pwd123 \
    -e YOURLS_DB_NAME=yourls \
    -e YOURLS_DB_HOST=127.0.0.1 \
    yourls

MySQL container should run on host network as well.

  • User-defined bridge network

User-defined bridge network can be used for listening on different port. By default, YOURLS service is listening on port 80. It can be changed with -p option.

docker network create app-net
docker run -d --name=yourls --restart=always --network=app-net \
    -p 8080:80 \
    -e YOURLS_SITE=http://192.168.0.252:8080 \
    -e YOURLS_USER=admin \
    -e YOURLS_PASS=pwd123 \
    -e YOURLS_DB_USER=root \
    -e YOURLS_DB_PASS=pwd123 \
    -e YOURLS_DB_NAME=yourls \
    -e YOURLS_DB_HOST=mysql \
    yourls

MySQL container should run on the same user-defined bridge network as well.

Notes:

  • Specify your hostname or IP address using YOURLS_SITE.
  • The YOURLS_DB_USER and YOURLS_DB_PASS can be used to specify MySQL credentials.
  • When user-defined bridge network is used, don't forget to change YOURLS_DB_HOST. It specifies MySQL container name.

Testing YOURLS

Open a web browser and go to http://<IP_ADDRESS>/admin, where <IP_ADDRESS> is the IP address of the system. Finish installation and log in to the dashboard using admin username and password.

YOURLS Inside Docker Container in Linux

Uninstall YOURLS

To completely remove YOURLS, remove its container:

docker rm --force yourls

Remove YOURLS image:

docker rmi yourls

If a user-defined bridge network was created, you can delete it as follows:

docker network rm app-net

Leave a Comment

Cancel reply

Your email address will not be published.