-
-
Notifications
You must be signed in to change notification settings - Fork 976
Add docker documentation #1446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Arcelone
wants to merge
13
commits into
mastodon:main
Choose a base branch
from
Arcelone:docker-documentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add docker documentation #1446
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4f4c94c
Add docker documentation
Arcelone 54e0fa6
Improved documentation and harmonized commands.
Arcelone 884dd30
Add Pre-requisites
Arcelone 7d9bf1e
Update git instructions
Arcelone 6280b48
Update the bigging of the compose section
Arcelone 998403d
Update the Setup section
Arcelone c7697ee
homogenization of the docker commands
Arcelone 4289aeb
Update pre-required to align with the official install method
Arcelone 340acea
Updated the repository retrieval method to be compatible with the def…
Arcelone 27bd266
Improve the section on generating the .env file and walk through the …
Arcelone 50689e3
Update nginx setup instruction to align with official systemd setup a…
Arcelone 26468b8
Remove the admin account confirmation step since now the admin accoun…
Arcelone 55fff54
Correction of errors, adjustment of syntax and style to match the ove…
Arcelone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| --- | ||
| title: Run Mastodon inside Docker | ||
| description: Setting Mastodon environnement using docker compose. | ||
| menu: | ||
| docs: | ||
| weight: 30 | ||
| parent: admin | ||
| --- | ||
|
|
||
| ## Pre-requisites {#pre-requisites} | ||
|
|
||
| * A machine running **Ubuntu 24.04** or **Debian 13** that you have root access to | ||
| * A **domain name** (or a subdomain) for the Mastodon server, e.g. `example.com` | ||
| * An email delivery service or other **SMTP server** | ||
| * Latest Docker version installed with compose plugin | ||
|
|
||
| {{< hint style="info" >}} | ||
| It's advised to reed the [security section](https://docs.docker.com/engine/security/) of the docker documentation. | ||
| {{< /hint >}} | ||
|
|
||
| You will be running the commands as root. If you aren’t already root, switch to root: `sudo -i` | ||
|
|
||
| ### Creating the `mastodon` user {#creating-the-mastodon-user} | ||
|
|
||
| This is the user account under which Mastodon will live: | ||
|
|
||
| ```bash | ||
| adduser --disabled-password mastodon | ||
| ``` | ||
|
|
||
| ### System packages {#system-packages} | ||
|
|
||
| ```bash | ||
| apt update | ||
| apt install -y certbot nginx python3-certbot-nginx | ||
| ``` | ||
|
|
||
| ## Setup {#setup} | ||
|
|
||
| ### Retrieve the last mastodon release {#retrieve-the-last mastodon-release} | ||
|
|
||
| ```bash | ||
| su - mastodon | ||
| # Clone Mastodon git repo | ||
| git clone https://github.com/mastodon/mastodon.git live | ||
| # Change directory to Mastodon repo | ||
| cd live | ||
| # Checkout to the latest stable branch | ||
| git checkout $(git tag -l | grep '^v[0-9.]*$' | sort -V | tail -n 1) && exit | ||
| ``` | ||
|
|
||
| ### Review the `docker-compose.yml` {#review-the-compose-file} | ||
| {{< hint style="info" >}} | ||
| If you want to enable ElasticSearch uncomment the `es` service in the `docker-compose.yml`. | ||
|
|
||
| If you want to enable federation with Tor instances uncomment the `tor` and the `privoxy` service in `docker-compose.yml`. | ||
| And and the following environment variable to the `.env.production`: | ||
|
|
||
| ```bash | ||
| http_hidden_proxy=http://privoxy:8118 | ||
| ALLOW_ACCESS_TO_HIDDEN_SERVICE=true | ||
| ``` | ||
| {{< /hint >}} | ||
|
|
||
| ### Generation of the `.env.production` file {#generation-of-the-.env.production-file} | ||
|
|
||
| To generate your `.env.production` file you have several options : | ||
| - Use the interactive setup wizard (recommended) | ||
| - Use the .env.production.sample | ||
| - Consult the [full config option list](https://docs.joinmastodon.org/admin/config/) and add the ones you need. | ||
|
|
||
|
|
||
| First start the **postgres** db and the **redis**. | ||
|
|
||
| ```bash | ||
| # Be sure to be root and in the /home/mastodon/live/ directory | ||
| # Pull all the images so you can work quickly later in the documentation | ||
| docker compose pull | ||
| # Start the Postgresql and the Redis database in detached mod | ||
| docker compose up db redis -d | ||
| ``` | ||
|
|
||
| By default, the db is configured without a password and with the other default parameters. If you wish to add a password to the db, or use a different user, table etc., you need to modify the `docker-compose.yml` to add the correct variables for the **Postgres** container of the db service. | ||
|
|
||
| Then launch the configuration wizard, which will display the `.env.production`. | ||
|
|
||
| ```bash | ||
| docker compose run --rm web bundle exec rake mastodon:setup | ||
| ``` | ||
|
|
||
| Fill in the required fields. | ||
| Finally, copy the contents of the generated `.env` and paste it into the `.env.production` on your machine. | ||
|
|
||
| Confirm the PostgreSQL setup. | ||
|
|
||
| {{< hint style="info" >}} | ||
| If for some reason you don't want to configure PostgreSQL now, you can run the following command later. | ||
| **Please note** this command requires the presence of the `.env.production` with the parameters to connect to the db: | ||
|
|
||
| ```bash | ||
| docker compose run --rm web bundle exec rails db:setup | ||
| ``` | ||
| {{< /hint >}} | ||
|
|
||
| Validate the creation of the admin account when requested and copy the generated password. | ||
|
|
||
| If the `mastodon:setup` script fails to initialize the db, add the variable `DISABLE_DATABASE_ENVIRONMENT_CHECK=1` in the container shell before re-running the command and validating the destruction of the database. | ||
|
|
||
| ```bash | ||
| docker compose run -e "DISABLE_DATABASE_ENVIRONMENT_CHECK=1" --rm web bundle exec rake mastodon:setup | ||
| ``` | ||
|
|
||
| You can now start all the Mastodon instance components. | ||
|
|
||
| ```bash | ||
| docker compose up -d | ||
| ``` | ||
|
|
||
| ## Reverse-proxy configuration {#Proxy configuration} | ||
|
|
||
| To access the Mastodon web instance you need to configure a proxy, like Nginx. | ||
|
|
||
| The mastodon web and streaming service are listening on 127.0.0.1 so you need setup nginx to redirect the traffic from port 80 and 443 of you machine to the web and streaming container which are listening on 127.0.0.1. | ||
|
Arcelone marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### Acquiring an SSL certificate {#acquiring-an-ssl-certificate} | ||
|
|
||
| We’ll use Let’s Encrypt to get a free SSL certificate: | ||
|
|
||
| ```bash | ||
| certbot certonly --nginx -d example.com | ||
| ``` | ||
|
|
||
| This will obtain the certificate, and save it in the directory `/etc/letsencrypt/live/example.com/`. | ||
|
|
||
| ### Setting up NGINX {#setting-up-nginx} | ||
|
|
||
| Copy the configuration template for nginx from the Mastodon directory: | ||
|
|
||
| ```bash | ||
| cp /root/mastodon/dist/nginx.conf /etc/nginx/sites-available/mastodon | ||
| ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon | ||
| rm /etc/nginx/sites-enabled/default | ||
| ``` | ||
|
|
||
| Then edit `/etc/nginx/sites-available/mastodon` to | ||
|
|
||
| 1. Replace `example.com` with your own domain name | ||
| 2. Uncomment the `ssl_certificate` and `ssl_certificate_key` (ignore this step if you are bringing your own certificate): | ||
|
|
||
| ```nginx | ||
| ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; | ||
| ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;; | ||
| ``` | ||
|
|
||
| 3. Uncomment the `# try_files $uri @mastodon;` instruction in the `location ^~ /assets/`, `location ^~ /packs/` and `location ^~ /system/` scop. | ||
|
|
||
| Allow other users to traverse the mastodon user's home directory, so that nginx's `www-data` user can access asset files: | ||
|
|
||
| ```bash | ||
| chmod o+x /home/mastodon | ||
| ``` | ||
|
|
||
| Restart nginx for the changes to take effect: | ||
|
|
||
| ```bash | ||
| systemctl restart nginx | ||
| ``` | ||
|
|
||
| At this point, you should be able to visit your domain in the browser. If you didn't create the admin account with the wizard follow the additional step. | ||
|
|
||
| ## Additional step {#Additional-step} | ||
| Connect to the web container and create the admin account, don't forget to approve the account. | ||
|
|
||
| ```bash | ||
| docker compose exec -it web bash | ||
|
|
||
| tootctl accounts create \ | ||
| alice \ | ||
| --email alice@example.com \ | ||
| --confirmed \ | ||
| --role Owner | ||
|
|
||
| tootctl accounts approve alice | ||
|
|
||
| exit | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.