Google Cloud Compute Engine

Install WordPress with Docker Compose using Nginx – Google Cloud

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

Install WordPress with Docker Compose using Nginx on Google Cloud Platform. In this article you are going to learn how to install and configure WordPress with Nginx, PHP-FPM on Google Cloud with Docker, Docker Compose and connect to Cloud SQL. We will also install PhpMyAdmin and connect it with Cloud SQL.

This setup is tested on Google Cloud Platform, it will also work on other cloud services, any VPS or any Dedicated servers with Docker.


  1. Your Compute Engine Instance running.
  2. For setting up Compute Engine, see the Setting up Compute Engine Instance.
  3. Install Docker on Google Cloud Platform.
  4. Install Docker Compose on Google Cloud.
  5. Set up Cloud DNS, see the Setting up Google Cloud DNS for your domain.
  6. Google Cloud SQL Setup, see Setup Cloud SQL and connect with Compute Engine.

This setup can also be installed on any Linux based servers.

Step 1: Setup Directories

Once you have Docker, Docker Compose installed and the Cloud SQL is setup you can proceed to setup directories for the WordPress installation.

SSH to your instance and create the directories as follows.

sudo mkdir wordpress-docker
cd wordpress-docker

sudo mkdir nginx
sudo mkdir wordpress
sudo mkdir -p logs/nginx

We will use these directories as volumes for our installation.

Step 2: Configure Nginx

Create a new Nginx configuration inside the nginx folder.

sudo nano nginx/wordpress.conf

Copy the below configurations.

server {
     listen 80;
     listen [::]:80;

     root /var/www/html; 
     index index.php;
     location / {
         try_files $uri $uri/ /index.php$is_args$args;

     location ~ .php$ {
         try_files $uri =404;
         fastcgi_split_path_info ^(.+.php)(/.+)$;
         fastcgi_pass wordpress:9000;
         fastcgi_index index.php;
         include fastcgi_params;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         fastcgi_param PATH_INFO $fastcgi_path_info;

     location ~ /.ht {
         deny all;

     location = /favicon.ico { 
         log_not_found off;
         access_log off; 

     location = /robots.txt { 
         log_not_found off;
         access_log off;
         allow all; 

     location ~* .(css|gif|ico|jpeg|jpg|js|png)$ {
         expires max;
         log_not_found off;

Step 3: Setup Docker Compose File

Create a docker-compose.yml file and include the configurations for WordPress.

We will create a container for Nginx and another container for WordPress and connect it to Cloud SQL.

We will also setup PhpMyAdmin to manage the database.

sudo nano docker-compose.yml

Copy and paste the below configurations in your docker compose file.

version: '3'
     image: wordpress:5.2.2-php7.2-fpm
     container_name: wordpress
     restart: unless-stopped
         - '9000:9000'
       WORDPRESS_DB_NAME: Database_name
       WORDPRESS_DB_USER: Database_user_name
       WORDPRESS_DB_PASSWORD: Database_user_password
       - ./wordpress:/var/www/html

     image: nginx:latest
     container_name: nginx
     restart: unless-stopped
       - "80:80"
       - "443:443"
         - ./nginx:/etc/nginx/conf.d
         - ./logs/nginx:/var/log/nginx
         - ./wordpress:/var/www/html
       - wordpress

     image: phpmyadmin/phpmyadmin
     restart: unless-stopped
       - 3333:80
       PMA_HOST: Cloud_SQL_IP_Address
       MYSQL_ROOT_PASSWORD: Cloud_SQL_Root_Password 

Now we have our docker-compose.yml file setup which a wordpress container wit the latest WordPress image with PHP 7.2 FPM. It will also creates an nginx container and configure it with the configuration we created above.

This will also downloads the phpmyadmin image and configure it on a different port and connects it with Cloud SQL.

Step 4: Run Docker-Compose

Now we have the Nginx configuration and Docker Compose configuration ready to be deployed.

Move to the folder that has your docker-compose.yml file and execute the following command to setup WordPress with Docker containers.

cd ~/wordpress-docker
docker-compose up -d

Now the containers are created using the configured images and will be accessible with the volumes we have created.

Once the setup is completed you can run this command to check the containers.

Step 5: Setup Firewall rules

As we have configured PhpMyAdmin on custom port 3333, we need to open the port in Firewall.

Go to VPC Network >> Firewall rules and click Create Firewall rules.

In Name enter phpmyadmin

In Targets select All instances in the network

In Source filter select IP ranges

In Source IP ranges enter

In Protocols and ports check TCP and enter 3333.

Click Create.

Step 6: Verify WordPress Installation with Docker

Once the setup is complete go to your browser and check your domain name.

You will see the default WordPress installation screen. Go ahead and install WordPress.

To check the PhpMyAdmin you can use the port 3333

This is connected with Cloud SQL, you can manage your Cloud SQL database from here.


Now you have learned how to install WordPress with Docker and Docker Compose and install PhpMyAdmin and connect it to Cloud SQL.

1 Comment

  1. Why is /var/www/html visible in the nginx container?
    ( – ./wordpress:/var/www/html )
    This does not feel secure, because nginx is a reverse proxy that hides the servers behind it, and yet you make the /var/www/html visibl ein the nginx container.

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.