Semi automated multiple ghost deployment in a single server via Shell & Docker

a simple script which will deploy multiple ghost instances in a single server almost automatically.

Semi automated multiple ghost deployment in a single server via Shell & Docker


Install docker

Install docker-compose

sudo apt install docker-compose

Install nginx

sudo apt install nginx

Note: In this script Cloudflare’s origin SSL used.

Create a file & paste the below code to the file & dont forget to adjust the db password

read -p 'Enter you domain name: ' domain
read -p 'Enter Port: ' port
# Stack Directory
mkdir -p $domain && mkdir -p $domain/content
# create the docker compose file
touch $domain/docker-compose.yaml
# Create the Nginx server block file:
sudo tee $block > /dev/null <<EOF
server {
  listen 80;
  listen [::]:80;
  server_name $domain www.$domain;
  location / { return 301 https://$host$request_uri; }
server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  server_name $domain www.$domain;
ssl_protocols TLSv1.2;
  ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;
  ssl_prefer_server_ciphers on;
  ssl_session_cache shared:SSL:10m;
ssl_certificate     /etc/ssl/; #define your ssl cert path
  ssl_certificate_key /etc/ssl/; #define your private key path
location / {
# docker-compose file configuration
tee $docker > /dev/null <<EOF
version: '3'
    container_name: ${domain}
    image: ghost:latest
    restart: always
      - ${port}:2368
      - ./content:/var/lib/ghost/content
      url: https://${domain}
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: ${password} #define a password here
      database__connection__database: ${domain}
    container_name: ${domain}_db
    image: mysql:5.7
    restart: always
      MYSQL_ROOT_PASSWORD: ${password} #define a root password for your container
# Link to make it available
sudo ln -s $block /etc/nginx/sites-enabled/
# Test configuration and reload if successful
sudo nginx -t && sudo service nginx reload
cd /home/$USER/$domain
#Deploy ghost
docker-compose up -d

Save the file & run below command

chmod +x

Now you should be able to deploy your ghost instance by running the script below


Now the script will ask you the domain name & Port
Once the domain name & port number submitted the script take care of your ghost deployment from creating nginx server block to Ghost installation.

Hope it will help them who requires multiple ghost installations quickly in a single server.

This article also posted on my Medium Account