Setup Ghost and Caddy with Docker on CentOS

Ghost is open source blogging platform, you can check more about ghost here.

To give you better example of the use-case this website itself is using ghost and is hosted on cloud.

Before you continue make sure to have CentOS running VM and have some basic Docker knowledge for better understanding.

Install Docker

  • Make sure system is up-to-date
$ sudo yum check-update
  • Install required packages.
$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
  • Use the following command to set up the stable repository.
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
  • Install Docker community edition
$ sudo yum install docker-ce docker-ce-cli containerd.io
  • Start Docker
sudo systemctl start docker
  • To make sure installation is successful try the following commands
sudo docker run hello-world
  • To give user permission to use docker without sudo add user to docker group.
sudo usermod -aG docker $USER

To learn more about Docker installation process, check the official Docker page here.

Install Ghost

  • Let's create directory where we want to setup ghost. Make sure to replace the USER value with your username.
mkdir /home/USER/ghost && cd ghost
  • Now we will install ghost with docker using following command. Make sure to replace the URL and USER with your domain name and centos user.
docker run -d \
  --restart always \
  --name ghost-blog \
  -v /home/<USER>/ghost/content:/var/lib/ghost/content \
  -p 2368:2368 \
  -e url= <HTTPS:YOUR DOMAIN> \
  ghost
  • Make sure your docker container is up
docker ps

Install Caddy

  • Before we install Caddy let's create Caddyfile in our ghost directory.
$ vi Caddyfile

$ <https://your.domain.com> {
    proxy / ghost-blog:2368 {
        transparent
    }
    tls <your email id>
}
  • Perfect now you are ready to install Caddy using Docker. Make sure to replace USER.
docker run -it \
  --restart always 
  --link ghost-blog:ghost-blog \
  --name caddy \
  -p 80:80 \
  -p 443:443 \
  -v /home/<USER>/ghost/Caddyfile:/etc/Caddyfile \
  -v /home/<USER>/.caddy:/root/.caddy \
  abiosoft/caddy
  • Here with -it you will see the logs of installation and is prompted you can give input. If everything is successful do Ctrl + P and then Ctrl + Q to get out of docker bash.
  • To make sure both the containers are running fine. Check the running docker containers.
docker ps
  • Now if you go to your <www.domain.com/ghost> you should see the ghost admin page.

Extras

  • Make sure the firewall are open for port 80 and 433 for your site to run. You can do it by using the following command
$ sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
$ sudo firewall-cmd --permanent --zone=public --add-port=443/tcp
$ sudo firewall-cmd --reload
  • Hopefully this article helps you setup the ghost website.
Show Comments