Deploy ghost with Docker

Deploy ghost with Docker

Docker makes it easy to deploy multiple ghost instances in a single server.

For this article I am choosing Ubuntu 20.04. & Make sure docker is installed in your system. You can find docker & docker-compose installation guide here >

Login to your server via ssh

[email protected]

Now create a folder to contain the docker-compose.yaml & docker volumes.

cd 
mkdir yourdomain.com

now create a file called docker-compose.yaml into the folder you have just created

nano docker-compose.yaml

& paste the following

version: '3'
services:
ghost:
    container_name: yourdomain.com
    image: ghost:latest
    restart: always
    ports:
      - 10000:2368
    volumes:
      - ./content:/var/lib/ghost/content
    environment:
      url: https://www.yourdomain.com
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: specifypasswordhere
      database__connection__database: yourdomain_production
db:
    container_name: yourdomain.com_db
    image: mysql:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: specify-password-here
    command: --default-authentication-plugin=mysql_native_password
	volumes:
      - ./data:/var/lib/mysql

Note: its good practice when you use custom port then it should start from 10000… eg. 10000 10001 etc

now save the file & run docker-compose up -d to start the stack. It should start just fine

Now configure the nginx server block

sudo nano /etc/nginx/sites/available/yourdomain.com

& past the following & Update the port same as your docker container

server {
  listen 80;
  listen [::]:80;
  server_name yourdomain.com www.yourdomain.com;
  location / { return 301 https://yourdomain.com$request_uri; }
}
server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  server_name yourdomain.com www.yourdomain.com;

  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/$domain/cert.pem; #define your ssl cert path
  ssl_certificate_key /etc/ssl/$domain/key.pem; #define your private key path

  location / {
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://0.0.0.0:10000; #define the port as your container
    
 }

}

save the file & link it to sites-enabled

sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/

check the nginx configuration

sudo nginx -t

restart nginx

sudo systemctl restart nginx

now your blog should be up & running. To add a new ghost instance repeat the process

If you prefer No-Code solution to deploy ghost then checkout

Spookey! - Managed Ghost Publication Specially for NoCode Lovers
You've successfully subscribed to Visioun Blog
Great! Next, complete checkout for full access to Visioun Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.