So, you’ve been weeping when you tried to execute the import script inside the docker container, it telling you that you haven’t got the mysql gem installed even though you have. You’ve been trying for hours to setup a dev instance of discourse, failing hard. Weep no more, this will solve all your problems.
First we are going to set up a docker instance called ‘import’, which includes the mysql dependency, then we will set up the mysql database as an additional docker container ( if you cant access it otherwise) and then we will run the import script.
1.1. Installing Discourse
Install Discourse by following the official installation guide.
1.2. Preparing the Docker container
Copy the container configuration file
import.yml and edit it with your favorite editor.
cd /var/discourse cp containers/app.yml containers/import.yml nano containers/import.yml
- "templates/import/mysql-dev.template.yml" to the list of templates. Afterwards it should look something like this:
templates: - "templates/postgres.template.yml" - "templates/redis.template.yml" - "templates/web.template.yml" - "templates/web.ratelimited.template.yml" ## Uncomment these two lines if you wish to add Lets Encrypt (https) #- "templates/web.ssl.template.yml" #- "templates/web.letsencrypt.ssl.template.yml" - "templates/import/mysql-dev.template.yml"
That’s it. You can save the file, close the editor and build the container and you will finally have mysql support inside your container.
/var/discourse/launcher stop app /var/discourse/launcher rebuild import
2. Setting up the mysql database - optional
You don’t have to do this step, if you can already access your database from within the docker container.
Put the mysql backup onto the machine you are running the discourse instance, change to the directory that contains the backup and start a mysql database instance like this:
docker run -d -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=db -v "$PWD":/backup --name=mysql mysql
Now enter the docker instance
docker exec -it mysql bash
and import the database
mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE < /backup/yourbackup.sql logout
finally grep your instances IP address for usage during the import
docker inspect mysql | grep IPAddress
3. Running the import script
Enter the import container you’ve created
cd /var/discourse ./launcher enter import
Open the bbpress import script
and adapt the mysql configuration
@client = Mysql2::Client.new( host: "172.17.0.X", username: "user", database: "db", password: "pass", )
Now you are good to go, to import run the script like this
su discourse -c "bundle exec ruby script/import_scripts/bbpress.rb"
Hopefully it succeeded and you can now move on to your next big thing!