In the past few days, I've seen a number of people having trouble getting Lemmy set up on their own servers. That motivated me to create Lemmy-Easy-Deploy, a dead-simple solution to deploying Lemmy using Docker Compose under the hood.
To accommodate people new to Docker or self hosting, I've made it as simple as I possibly could. Edit the config file to specify your domain, then run the script. That's it! No manual configuration is needed. Your self hosted Lemmy instance will be up and running in about a minute or less. Everything is taken care of for you. Random passwords are created for Lemmy's microservices, and HTTPS is handled automatically by Caddy.
Updates are automatic too! Run the script again to detect and deploy updates to Lemmy automatically.
If you are an advanced user, plenty of config options are available. You can set this to compile Lemmy from source if you want, which is useful for trying out Release Candidate versions. You can also specify a Cloudflare API token, and if you do, HTTPS certificates will use the DNS challenge instead. This is helpful for Cloudflare proxy users, who can have issues with HTTPS certificates sometimes.
As someone who spent hours figuring out how to deploy through Ansible, how dare you /s But seriously thank you for putting in the work to make creating an instance more attainable for people.
I'm just a novice hobbyist (the only server I've put together was a homebridge server years ago) so the learning curve for this was relatively high putting together a VPS, setting up ssh, learning how to properly configure, and there were some errors when running the playbook I had to slowly figure out. Honestly though once it was all done, I thought "man, that was actually pretty easy" and I learned a lot so that was really cool
seriously, distributing the load helps a LOT. Though if you can't spin up your own instance one thing you can do is try and host pictures externally, in !youshouldknow[email protected] a post mentioned how to do it for images in comments since by default it has you upload if you don't manually put in ![image](link)
Been pounding my head against the desk for the last TWO DAYS trying to get everything to work. Then you came along and solved all of my problems and it only took me 10 minutes to set up (mostly due to waiting on DNS to flush!)
THANK YOU SO MUCH for creating this, and PLEASE continue to maintain! I will gib coffees if need be along the way!!
It will work on pretty much anything that has a public IP and a domain pointing to that IP. The only thing that won't work "out of the box" for most users is email, as most VPS providers block port 25. If you've requested access to port 25 and have been approved to use it, you can edit config.env to turn on the email service.
As for your SSL certificate, unfortunately this does not support importing your own certificate. It's made for beginners, after all :p
But there should be no problems with Caddy simply requesting a new one for you!
how well do those email servers work to begin with? i just flat out disabled the postfix relay on my instance and simply configured sendgrid, which works perfectly, no delays or spam folder issues (although i did have to disable a bunch of tracking bullshit). doing so with similar services has been my go-to card in freelance webdev, because getting other mail servers to trust you can be hard, so i'm interested in the experience people are having with those. (i'd much prefer to self-host email too, but providing a good experience is the primary goal)
You kind Sir/Lady/Gentleperson are making the fediverse a better place with this help. Thanks a bunch, gonna definitely ease my attempts at eventually self-hosting!
Looks great my dude.
If you expanded out the environment variables a ton, making it more customizable, (with default values in place of couse) this could appeal to a huge range of people.
Can you explain? I provide an interface for everything available in lemmy.hjson, so I am not sure what else I would add.
I will note though, this is primarily intended for beginners. More advanced users would probably prefer to manage this on their own with Docker Compose, and those people will be very well versed in messing with the environment variables and all that.
If there are variables you want to pass in, you can simply edit docker-compose.yml.template to import an env_file, that way you can pass anything you want into the container.
Quick note: For email, pretty much every VPS provider out there blocks port 25, which is needed for emails to send. They do this to prevent spam emails from being sent en-masse from their servers. This is likely why your Ansible installation is not sending emails.
Since it's uncommon for servers to support email, this script disables it by default. If your provider supports port 25 (or you get approved to use it, some VPS providers allow you to request access), check config.env and set USE_EMAIL to true. This will set up everything you need for email.
I haven't been able to test email, so let me know how it works if you do! This doesn't do any of the DNS verification some email provders require, so your emails might be sent to spam. Lemmy doesn't really have documentation about how to set this up properly. If someone makes guidelines for this, I can update my project to do that automatically as well.
Did you figure out how to run this right from the docker portion of unraid? I'm about to get mine going and I'm probably just going to start a Ubuntu vm.
Sorry, I don't have access to an unRaid system to test it with.
However, I know most NAS systems at least support CLI-style Docker and Docker Compose, so if you can manage to get Docker running, it might work? The script has some Docker detection if you're not sure.
However, I know Synology hogs use of port 80 and 443. I'm not sure if unRaid is the same way. If it is, this might not be the best solution for you. But, if you want to give it a shot, I do have some advanced options in my config that lets you change to different ports and turn off HTTPS (so you can run a proxy in front of it). I can't really help people who run it behind a webserver like this, but the template files in my repo can be freely modified, so you're welcome to hack at my script any way you like to get it working!
Nice! Looks like it even has update checker as well. Is there any reason why pictrs is not included in the update checker and hardcoded to version 0.3.1?
The Lemmy maintainers themselves seem to lock it at 0.3.1, and I wanted to maintain parity with their deployment. I know pictrs is up to at least 0.3.3, and has a release candidate for 0.4, but upstream Lemmy uses 0.3.1 for whatever reason, so that's why I lock it there.
It's excluded from the update checker because I don't have a stable way to check what version upstream is using. The Lemmy update checker just checks to see what the latest tag on LemmyNet/lemmy is. I could try and pull the latest Gitea tag for pictrs, but since upstream Lemmy isn't using the latest version, that's not really an option as something might break.
I considered trying to parse their docker-compose.yml file to see what version they use, but they seem to be restructuring their docker folder right now. The folder in main is completely different from the one tagged 0.17.4. If I assume a certain directory path for that file for every version after this, but they move it, my script will break. Sadly, until their Docker deployment files seem like they're going unchanged for a good few versions, I'll have to do it manually for now.
I haven't tested a local only use case, but you can probably set these options in config.env
Set LEMMY_HOSTNAME to localhost
Set CADDY_DISABLE_TLS to true
Set TLS_ENABLED to false
This will disable any HTTPS certificate generation and only run Lemmy on port 80. I don't know if Caddy or Lemmy will act weird if the hostname is localhost, but this should work for you. Let me know if it doesn't.
SOLVED: The problem was caused because I was using a | In the site name SETUP_SITE_NAME
for some reason the bash script is returning sed: -e expression #7, char 32: unknown option to `s'
I 've looked online and found nothing that related to my problem.
I suspect the problem starts in line 253 because the file lemmy.hjson is empty and the docker-compose.yml isn't created.
I didn't bother, as I was just testing. But you are right, port 25 outbound is blocked by default. They have a defined process for you to ask for it to be unblocked and you have to tell them what you are using it for and how you are preventing spam from being sent. In this case it might be enough to say that you aren't allowing port 25 inbound, so it can't be used as an open relay.
So stupid question - how do you shut them down? Docker compose down or stop don't seem to work.
Also, as an intermediate (spoiled Unraid) user, if I'm behind nginx proxy manager with custom ports do I just change 80 and 443 in the lemmy docker-compose? I'm doing this in a Debian VM.
I'll add some better instructions for this to the readme.
You can do any Docker compose commands by changing to the ./live folder, then running:
docker compose -p lemmy-easy-deploy <command>
<command> can be whatever Docker Compose supports, up,down,ps, etc.
I don't have config options for the ports, but you can just change them in docker-compose.yml.template to change what they're listening on. As long as yourdomain.com:80 is reachable from the public, it shouldn't matter what routing shenanigans are going on behind it.
This was the only tool that I was able to get running. I recommend it to anyone curious about running their own instance. I tried both the official Ansible and Docker instructions, and neither worked.
Thank you for this. One suggestion though, on the config prompt where it says to not use http or https, maybe suggest to DO use www.. I'm a potato and didn't include that and made caddy mad. It would be helpful for other potatoes.
This was absolutely amazing. I was having some trouble with the build process using the docker compose from Lemmy itself, but this just instantly worked. Thank you!
A bit OT, but worth the shot: can anyone confirm whether instances deployed with this script can be found on Mastodon?
I have tried both the ansible script provided by the developers and I've adapted the docker-compose files to get things running on Docker Swarm. Everything seems to be working well, object storage, federation... except that I can not find any user or community from my instance if I search from Mastodon.
I see this user who deployed using this script, I click the username link below his name which should lead to server.tld/u/username, but it leads to server.tld/users/username, maybe some kind of dbUser -> outside world configuration is broken?
Also the Bio is different on his local instance and the federated instance?
Thanks for the helpful tool! Posting this from my new single-user Lemmy instance. I ended up tweaking the compose template a bit to remove Caddy since I already have it running on this VPS for other services. Wasn't too bad to just take the Caddyfile information and add it to my own existing framework.
Does your user have permission to use Docker? You could try running the script as root and seeing if that helps?
Is there any other info about your system that you can provide? For example, are you using a non-standard OCI runtime, such as podman? I've added detection for podman-compose in the script, but I haven't tested it yet. If you're using something like that, you'll need to ensure all the permissions are set up correctly.
Before this week, I would have told you no. But I have big plans for the 0.18.1 update.
The Lemmy team has completely broken ARM support with seemingly no plan to support it again. They switched to a base Docker image that only supports x86_64. This is why your build fails. I still don't understand why they would move from a multiarch image to an x86_64-only one.
I've been working on this for about a week, and just yesterday I finished a GitHub Actions pipeline that builds multiarch images for x64/arm/arm64. I currently have successful builds for 0.18.1-rc.2. In a future update for my script, I will have it use these, that way ARM users don't need to compile it anymore. I just ask for a little patience, I haven't been able to do any work on Lemmy Easy Deploy since I've been working on this pipeline :)
I also do want to qualify - don't get your hopes up until you see it running for yourself. Ultimately, I am just a DevOps guy, not a Lemmy maintainer. I haven't tested my ARM images yet, and while I did my best to get these to build properly, I can't fix everything. If anything else breaks due to running on ARM, it will be up to the Lemmy team to fix those issues (which is not likely anytime soon, if their updated x86_64 Dockerfiles are any indication).
But, fingers crossed everything goes smoothly! Keep an eye out for an update, I'm working hard on it, hopefully I can get it out in time for 0.18.1!
Thanks for the update, I updated to 0.18.0 a few days ago and it worked perfect. I'm excited for the next update, hopefully the Lemmy devs dont make big updates like this in future releases.
Try again with the latest version of Lemmy Easy Deploy.
I am now building multiarch images for 0.18.x, and my script will now default to my multiarch images, so there is no longer a need to build it yourself :)
This is really cool! I was having issues with the websocket when trying to run the setup locally from the docs, but this worked smoothly out of the box!
I'd be interested in adding a ./deploy.sh --migrate-export, and a ./deploy.sh --migrate-import, so people can export and import their volumes easily. This could be useful if people needed to upgrade their machines or move hosts
This is really great. I wish I could use it, but unfortunately I'm already using a different reverse proxy and can't use the included Caddy instance. Perhaps someone else will be able to do something similar for those in my situation. Great work, though!
Any ideas how to solve this? Everthing works according to docker..
XXXXX@lemmy:~/Lemmy-Easy-Deploy$ ./deploy.sh
Lemmy-Easy-Deploy by ubergeek77 (v1.1.1)
Detected runtime: docker (Docker version 24.0.2, build cb74dfc)
Detected compose: docker compose (Docker Compose version v2.18.1)
Runtime state: ERROR
ERROR: Docker runtime not healthy.
Something is wrong with your Docker installation.
Please ensure you can run the following command on your own without errors:
docker run --rm -it -v $(pwd):/host:ro hello-world
If you see any errors while running that command, please Google the error messages
to see if any of the solutions work for you. Once Docker is functional on your system,
you can try running Lemmy Easy Deploy again.
XXXXX@lemmy:~/Lemmy-Easy-Deploy$ sudo docker run --rm -it -v $(pwd):/host:ro hello-world
[sudo] password for XXXXX:
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
The Docker client contacted the Docker daemon.
The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
I am biased, but I would say yes, it is. There is only one config file to manage in my project, whereas the Ansible config has three separate config files the user needs to copy and edit.
You also need* a different system with Ansible installed to actually run the playbook, since Ansible needs to connect to your server to run it. That is an extra installation step, on top of needing some way to ensure Ansible has the right SSH credentials to connect.
*you can tell Ansible to connect to localhost, but this is not supported and a beginner wouldn't know to do this.
There is nothing wrong with the playbook though! I just thought beginners might be a bit intimidated by it, and the dependency on apt is a bit of a bummer.
I must be doing something wrong here because unlike many others I can't seem to get this working! Please can you offer some advice?
I have amended the config.env file to change the HOSTNAME, SITE NAME and ADMIN USER but left everything else the same.
I then ran ./deploy.sh and everything seems to have worked because it presented me with the admin login credentials and basic instructions to shutdown and start the instance. I tried simply typing the IP address of the docker container in to a browser but that didn't work and TBH I didn't expect it to. I then typed the URL into the browser and I'm getting a "ERR_TOO_MANY_REDIRECTS" error message. I read through the trouble shooting on your Github but the only reference to too many redirects mentions a Cloudflare API token, I'm not using Cloudflare nut I am using nginx proxy manager to point my URL to the docker container.
Hey there, please note that running behind a reverse proxy is not supported. You can do it if you want, but you are kinda on your own, sorry.
If it helps, you will probably need to disable Caddy's TLS in the config, and you will need to make sure that the request reaches Caddy via the correct host. You can't reverse proxy directly to port 80 over an IP, it needs to think it's coming from an actual domain.
You can also check out my advanced configuration page to learn how to override the Caddyfile template and roll your own config that is more compatible for your use case.
I appreciate the effort, but for software as experimental as Lemmy I would argue making things 1-click "simple" will inevitably lead to people breaking their instances in the future, when some migration will be required.
I would strongly suggest people figure things on their own.