LanCache Docker (Manual) - uthomelabs/guides GitHub Wiki

Ever wish you could just cache your games? Rather than waiting for them to download from the internet every time you reinstall? Well now you can! Steam and many others are awesome and allow caching of the game content. Read through this guide, but if you want a slightly automated script guide can be found here

LanCache time!

This guide will help you get a LanCache(https://lancache.net/) up and running on your network. With LanCache, you can cache all your steam, epic, etc games! It doesn't work with all of them, but it does with all the major players! It will even cache Windows updates!

It is super simple to setup. All the documentation can be found at https://lancache.net/docs/

All you need is a linux computer, linux virtual machine, or anything that can run a docker container. And enough storage space for your caching needs.

I recommend mounting your large storage drive to the path that CACHE_ROOT points to (more on that later). I use a hypervisor with a storage mount located on my NAS. The storage drive is made using LVM so I can easily expand it as much as I need.

Installation

So go get Docker and Docker Compose installed and let's get started.

Static IP

Actually, before we get started. Make sure your machine has a static IP address. We don't want the IP address to ever change for your LanCache. Setting a static IP is out of the scope here, but set one either on the machine or on your router for that machine via DHCP. I love to use DHCP to set my devices to a static IP so I can see all my static devices from one interface. klipper will challenge me on this. But between you and me, I'm correct. :]

First clone the repository

git clone https://github.com/lancachenet/docker-compose/ lancache

cd into that new directory

cd lancache

Edit the .env file and update a few things.

vi .env

Change the LANCACHE_IP and DNS_BIND_IP to the IP of your LanCache machine.

Change the UPSTREAM_DNS if you don't want to use the default google 8.8.8.8 IP address. Otherwise leave it alone.

If your base storage drive is large enough, you can leave CACHE_ROOT alone. Otherwise, point it to a mount that is large enough to hold all the cached files. Or mount your large storage drive at the default location of ./lancache

Update CACHE_DISK_SIZE to slightly less than the amount of storage you have available for CACHE_ROOT. If you allocate more space, make sure you update this! You also have to destroy the docker container and rebuild it. I believe running docker-compose down --rmi all --remove-orphans will work. And the next time you bring it up, it will re-download all your images. Or running docker compose pull might also do the trick. But don't worry, your cache should stick around. See https://lancache.net/docs/upgrading/

And finally, update TZ to your time zone. For example TZ=America/Denver

Start the service.

docker compose up -d

Stop the service

docker compose down

Point DNS to your LanCache

Your router should be handing out an IP address for DNS. Change that IP address to your LanCache IP address. Now all of your devices will go to the LanCache for DNS, and the LanCache will go to the UPSTREAM_DNS for an answer. BUT, if the DNS request is for a steam/epic/etc game, it will check its cache and return the data or go out to the internet to retrieve it.

!!!WARNING!!! Doing this method will break your internet if your LanCache goes down for any reason. Which makes for a poor significant other approval factor. So make sure you keep it running! The alternative is to redirect specific DNS requests to your LanCache (ie lancache.steamcontent.com) but I had poor luck with doing that. It was very hit and miss if it worked. Mostly a miss.

Make it automatic

Love it or hate it, systemd will be our friend and help keep the significant other approval factor at an acceptable level.

Make a service file

Create this file /etc/systemd/system/lancache.service and fill it with this:

[Unit]
Description=lancache
Requires=docker.service
After=docker.service

[Service]
Restart=always
User=root
Group=docker
WorkingDirectory=/home/ubuntu/lancache
# Shutdown container (if running) when unit is started
ExecStartPre=/usr/bin/docker compose -f docker-compose.yml down
# Start container when unit is started
ExecStart=/usr/bin/docker compose -f docker-compose.yml up
# Stop container when unit is stopped
ExecStop=/usr/bin/docker compose -f docker-compose.yml down

[Install]
WantedBy=multi-user.target

Adjust the User and WorkingDirectory as needed.

Enable the service

systemctl enable lancache.service

Start the service

service lancache start

Get caching

Launch steam and start downloading a game. Now get back onto your LanCache and start tailing the log

tail -f ~/lancache/lancache/logs/access.log

You should see a bunch of requests hitting it with "MISS".

Check your cache

After your game is finished downloading, go ahead and delete it from your gaming computer. And start download it again. You should see your download speed significantly faster. Unless you used a Pentium II for your LanCache, then I'm sorry to hear this. But congrats on getting a modern OS installed on it!

Tail that log again and you should see a bunch of "HIT" logs. GAME ON!