Changing the hostname


(Jarrett Colby) #1

I installed Discourse with Docker per the official instructions.

At the time of installation, I didn’t have a domain name ready, so I just used an IP address as the hostname. Later, I got the domain name working, and Discourse is accessible via that hostname.

However, the IP address–which is no longer the correct hostname for this installation–still shows up in various places. One such place is outgoing emails. When a user receives a notification of a new post, the link back to the topic has the IP address as the hostname.

I’ve replaced the IP address where I could find it:

  • In the host OS at /var/discourse/containers/app.yml, the DISCOURSE_HOSTNAME key.
  • Inside the Docker container at /var/www/discourse/config/discourse.conf, the hostname key.

I tried SiteSetting.refresh! from the Rails console. I also tried restarting the Docker container with ./launcher restart app.

I see that in app/views/email/_post.html.erb, the links go to Discourse.base_url. From the Rails console, I see that Discourse.base_url is correct:

root@discourse:/var/www/discourse# rails console production
irb(main):001:0> Discourse.base_url
=> ""

Yet the outgoing emails still have the IP address instead of the correct hostname. Any idea why that would happen, and how it might be fixed?


I think rebuilding the container will resolve your issue. Double-check the hostname details in the app.yml and make sure they’re saved to your liking. Then rebuild Discourse’s container, which destroys the old one, bootstraps a new one, and starts it up.

Navigate to the Discourse directory:

cd /var/discourse

Then use the rebuild command:

./launcher rebuild app

Hope that helps!

(Jarrett Colby) #3

What becomes of the database upon a rebuild? Does it get wiped out? We already have content we’d like to preserve.

Instead of a rebuild, would it be possible to find where the setting is stored and edit it manually?


Rebuild preserves the database. If you still are paranoid, just make a backup and download that, it contains all users, posts, etc.


Fear not, the database is preserved through rebuilds. The only things that
could be “lost” are items mentioned in the app.yml. In this case, that
includes your old IP address! Also, if you ever want to install new
plugins, that process will also require app rebuilds.

(Ron Shannon) #6

If I’d known this, it would have saved a lot of woes about installation (and re-installation) woes. I assumed “rebuild app” meant starting over – not an unreasonable interpretation. I was trying to start over (and over, and over… ) but bits and pieces of previous attempts kept showing up, compounding confusion.


I think the documentation will continue to improve over time. That’s one area where we, the community, can help the core Discourse team.

(Ron Shannon) #8

Yes, and I’d like to help out with that. We’re getting a little OT here, but is there a group/project (etc.) for that you know about? TIA

(Eric Toombs) #9

Are you sure a rebuild is necessary? This post says a rebuild isn’t necessary for any changes to the env section.

update: I changed the hostname and restarted the service without rebuilding. It hasn’t exploded on me yet…