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

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


  • Install docker
  • Install docker-compose
     sudo apt install docker-compose
  • Install nginx
    sudo apt install nginx

Now lets check create the script

Create a file & paste the below code to the file

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 number
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.

You’ll probably want a persistent volume mounted, or to use a custom storage adapter so that you don’t blow away all your images if you need to rebuild the container

1 Like

Hey @fabien Thanks for the suggestion. I will follow the suggestion & update the code.


1 Like

The Above script is updated now with volumes for contents