How I Set Up My Personal Blog Using Ghost Engine and Docker

If you're interested in setting up your own personal blog, there are a lot of options available. I decided to use Ghost engine for its simplicity and flexibility, and Docker for its ease of use and portability.

Here's how I set up my personal blog using Ghost engine and Docker:

Step 1: Create Directories for MySQL Data

The first step was to create directories for MySQL data. This will help to ensure that the data is properly stored and can be accessed when needed.

To do this, you can use the following command:

sudo mkdir -p /opt/mysql/{data,etc}

This command will create two directories - one for storing the actual MySQL data, and one for storing configuration files for MySQL. The "-p" option is used to create parent directories if they don't already exist.

It's important to note that the directories can be named whatever you like, but it's a good idea to use descriptive names so that you can easily identify them later on.

Step 2: Start Up MySQL 8 Using Docker

Once the directories have been created, you can move on to setting up MySQL. This can be done using Docker, which makes it easy to set up and manage MySQL containers.

The following command can be used to start up MySQL 8:

docker run -d --restart=always \
--name mysql-server \
-v /opt/mysql/data:/var/lib/mysql \
-v /opt/mysql/etc:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=mysql_root_password \
mysql:latest

This command will start up a MySQL container with the name "mysql-server". The "-d" option is used to run the container in the background, and the "--restart=always" option is used to ensure that the container is automatically restarted if it crashes or is stopped.

The "-v" option is used to mount the directories that we created earlier, so that the MySQL data and configuration files can be stored in these directories. The "-e" option is used to set the root password for MySQL.

Step 3: Use Nginx as Frontend

With MySQL set up and running, you can move on to setting up the frontend for your blog. I decided to use Nginx as a frontend and I used the following command to start up Nginx:

docker run -d --restart=always \
--name nginx-proxy \
--publish 80:80 --publish 443:443 \
--volume certs:/etc/nginx/certs \
--volume vhost:/etc/nginx/vhost.d \
--volume html:/usr/share/nginx/html \
--volume /var/run/docker.sock:/tmp/docker.sock:ro \
nginxproxy/nginx-proxy

This command will start up a container with the name "nginx-proxy", which will act as a reverse proxy for our blog. The "--publish" option is used to map the ports for HTTP and HTTPS, so that the blog can be accessed via a web browser.

The "--volume" option is used to mount various directories and files that are needed by nginx. The "/var/run/docker.sock" file is also mounted, which allows the container to communicate with the Docker daemon on the host.

Step 4: Add Docker Container to Use SSL Certificates via Let's Encrypt

We need to add SSL certificates to our blog. This can be done using the Let's Encrypt service and the acme-companion Docker container.

The following command can be used to start up the acme-companion container:

docker run -d --restart=always \
--name nginx-proxy-ssl \
--volumes-from nginx-proxy \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
--volume acme:/etc/acme.sh \
--env "[email protected]" \
nginxproxy/acme-companion

This command will start up a container with the name "nginx-proxy-ssl", which will automatically request and renew SSL certificates for our blog. The "--volumes-from" option is used to mount the volumes from the "nginx-proxy" container, which allows the acme-companion container to access the necessary files and directories.

Step 5: Run Ghost Using Docker

Finally, we can start up our Ghost container using the following command:

docker run -d \
--name your_domain.com \
-v /opt/site_content:/var/lib/ghost/content \
--env "VIRTUAL_HOST=your_domain.com" \
--env "VIRTUAL_PORT=2368" \
--env "LETSENCRYPT_HOST=your_domain.com" \
--env "[email protected]" \
--env "url=https://your_domain.com"
--env "database__client=mysql" \
--env "database__connection__host=ip_address_mysql_host" \
--env "database__connection__user=root" \
--env "database__connection__password=mysql_root_password" \
--env "database__connection__database=db_name"
ghost

After running this command, the Ghost container will be up and running, serving your website on the specified domain name. You can access your website by navigating to the domain name you specified in your web browser.

Conclusion

In conclusion, setting up a personal blog using Ghost engine is not as hard as it may seem. By following the steps outlined in this article, you can have your blog up and running in no time. You can customize the look and feel of your blog by using different Ghost themes and plugins. If you are a developer, you can even create your own custom theme and plugin to make your blog unique.

Happy blogging!

Subscribe to The Code Sandwiches

Sign up now to get access to the library of members-only issues.
Jamie Larson
Subscribe