Yahya Uddin
Yahya Uddin

Reputation: 28951

Run existing Wordpress site using Docker

I want to run my existing Wordpress site on Docker for local development.

This is my docker-compose file:

version: '2'
services:
  mysql:
    image: mysql:5.7
    volumes:
      - "./.data/db:/var/lib/mysql"
    ports:
      - "9306:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example_password
      MYSQL_DATABASE: example_database_name

  wordpress:
    image: wordpress
    volumes:
      - "./:/var/www/html"
    links:
      - mysql
    ports:
      - "80:80"
    restart: always
    environment:
      WORDPRESS_DB_PASSWORD: example_password
      WORDPRESS_DB_NAME: example_database_name

However, the problem I have with the offical Wordpress Docker image is that it insists on installing Wordpress. This is fine if you don't have Wordpress installed, but causes a LOT of problems if already have it installed. This is especially frustrating because I organised my folders so all the internal wordpress files are in a separate folder called "wp", with "wp-content" on a separate directory.

So my question is how can I run my existing Wordpress site using Docker.

Upvotes: 1

Views: 3164

Answers (4)

Matianda
Matianda

Reputation: 171

Step 1: In the wordpress service block, you should update the volumes property as below:

volumes:
  - ./source:/var/www/html

source is the directory's name will be created in the same path that contains your WordPress's sourcecode. You can customize it to whatever name you want.

Step 2: Copy all sub-folders in your existing source inside wp-content to the new directory in Step 1 (source\wp-content)

Upvotes: 0

ldg
ldg

Reputation: 9402

Your best bet if you want to use the official image is going to be to mount the wp-content directory not the entire www directory, like:

-v /path/to/my/blog/wp-content:/var/www/html/wp-content

and adjust the custom set-up you have involving your "wp" directory. Wordpress expects a certain directory structure, so depending on why you broke out your files you may or may not be able to use the default container. The nice thing about using it this way is you can update WP simply by updating the container and all your files remain protected.

If you needs are too custom for that, as mentioned, you can try using the WP Dockerfile and edit to suit you needs, but if you can use the standard wp-content structure, it's going to make things simpler to manage and maintain.

Upvotes: 0

Haoming Zhang
Haoming Zhang

Reputation: 2852

With the official Wordpress image, Docker will starts a container which use Debian as base system, with apache, php and wordpress installed. If you don't like it, you can create your customized image by creating Dockerfile. You can discard any component that you don't need.

Upvotes: 1

Filip Dupanović
Filip Dupanović

Reputation: 33700

As a general advice, you should be able to mount your sources as a volume on paths that override existing individual files or complete directories to tailor the container to your needs.

Upvotes: 0

Related Questions