Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I setup a local wordpress using Docker?

So I decided to try Docker for my local Wordpress development.

Luckily, Docker has a quickstart guide for that.

I followed the entire process and I *think* I understood most of it. However, when I had the Docker container up and running, it made a clean installation of Wordpress instead of using the local files I had for a project. I initially thought that changing the directory to the project folder allowed it to read the files in it. Apparently, I was mistaken. I've tried searching the net for an answer and most of them are just tutorials into how to use Docker for WP.

So with that in mind, how do I create a Docker container (or change the Docker YAML file) that uses the local WP files I have?

docker-compose.yml

version: '3.3'

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
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}

Project structure

/project
  /app
  /sql
  docker-compose.yml

I'm running on Ubuntu 19.04

like image 992
zero Avatar asked Dec 07 '25 05:12

zero


2 Answers

Wordpress on docker

Create the docker-compose.yml with the follwing

version: '3.1'
services:
  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    volumes:
      - ./app:/var/www/html
    environment:
      WORDPRESS_DB_PASSWORD: DoKRteST
      WORDPRESS_DB_HOST: mysql
  mysql:
    image: mysql:5.7
    # Uncomment the below code to maintain the persistancy of the data 
    # volumes:
          # - ./wordpress:/var/www/html
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: DoKRteST

./app folder is the actual wordpress app folder

Simply click on Try in PWD to run it on Play with docker

like image 126
Jinna Balu Avatar answered Dec 08 '25 23:12

Jinna Balu


You just need to mount wp-content of the host to the container. you can look for wp-content in your current directory structure probably under app/wp-content

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     volumes:
        - wp-content:/var/www/html/wp-content
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress

You can read more details here and here

like image 32
Adiii Avatar answered Dec 09 '25 00:12

Adiii