How to run WordPress + Woocommerce Locally with Docker

Photo by Fikret tozak on Unsplash

For the last two days, I have been stuck in how to run a locally Wordpress Store with Woocommerce.

I have tried to use the (g)old LAMP with NGINX, docker images, whatever until find the easiest way.

An online frien…


This content originally appeared on DEV Community and was authored by Danilo Assis

Photo by Fikret tozak on Unsplash

For the last two days, I have been stuck in how to run a locally Wordpress Store with Woocommerce.

I have tried to use the (g)old LAMP with NGINX, docker images, whatever until find the easiest way.

An online friend on WordPress slack named Leandro shares a link from official docs on Docker where they explain how to run a WordPress store with two simple images.

This tutorial will be upon this link. There is explained how to create a new docker-compose file to compose an image from MySQL and WordPress to have locally your store.

The link is here Quickstart: Compose and WordPress and before continuing check it and create the docker-compose file in a local folder in your machine.

Editing the files locally

Let's edit our docker-compose.yml file to bring the content from containers to our local machine.

From this, we can edit the files locally and reproduce whatever we want on the local store.

For example, we can use this to create a new payment plugin.

  • Open the docker-compose.yml and replace for this code:
version: "3.9"
services:
  db:
    image: mysql:5.7
    volumes:
      - ./db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - ./wordpress:/var/www/html
      - ./plugins:/var/www/html/wp-content/plugins
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress

Here we use volumes to make available locally the folders we want to have access to.

Look to the lines 17, 18, and 19. It is where we ask to transform the content of folders into volumes. Thanks for Fernando Almeida, a friend from React Brasil slack helped me with this.

Now, on the root folder as the same as the docker-compose file, run docker-compose up -d to mount our containers and images.

compose

Now, the folders db_data, plugins and WordPress must be available locally and you can start your development work o/!!

folders

The wordpress site
site

Woocommerce Store

Until here we just have a simple WordPress blog. My use case needs to have a woocommerce store.

To get it we need to complete the simple steps explained below

Step 1 - Install a storefront theme

Let's install a theme to transform our website in a store. The default theme of WordPress is a blog site and is not what we want.

Dashboard > Appearance > Themes > Add new and search for "storefront".

Step 2 - Install the woocommerce plugin

Install the woo-commerce plugin similar to the last step:

Dashboard > Plugins > Add new and search for "woocommerce"

Now, your store is completely configured to be used locally
image

The repo is available here docker-wordpress


This content originally appeared on DEV Community and was authored by Danilo Assis


Print Share Comment Cite Upload Translate Updates
APA

Danilo Assis | Sciencx (2021-07-30T23:01:50+00:00) How to run WordPress + Woocommerce Locally with Docker. Retrieved from https://www.scien.cx/2021/07/30/how-to-run-wordpress-woocommerce-locally-with-docker/

MLA
" » How to run WordPress + Woocommerce Locally with Docker." Danilo Assis | Sciencx - Friday July 30, 2021, https://www.scien.cx/2021/07/30/how-to-run-wordpress-woocommerce-locally-with-docker/
HARVARD
Danilo Assis | Sciencx Friday July 30, 2021 » How to run WordPress + Woocommerce Locally with Docker., viewed ,<https://www.scien.cx/2021/07/30/how-to-run-wordpress-woocommerce-locally-with-docker/>
VANCOUVER
Danilo Assis | Sciencx - » How to run WordPress + Woocommerce Locally with Docker. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/30/how-to-run-wordpress-woocommerce-locally-with-docker/
CHICAGO
" » How to run WordPress + Woocommerce Locally with Docker." Danilo Assis | Sciencx - Accessed . https://www.scien.cx/2021/07/30/how-to-run-wordpress-woocommerce-locally-with-docker/
IEEE
" » How to run WordPress + Woocommerce Locally with Docker." Danilo Assis | Sciencx [Online]. Available: https://www.scien.cx/2021/07/30/how-to-run-wordpress-woocommerce-locally-with-docker/. [Accessed: ]
rf:citation
» How to run WordPress + Woocommerce Locally with Docker | Danilo Assis | Sciencx | https://www.scien.cx/2021/07/30/how-to-run-wordpress-woocommerce-locally-with-docker/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.