Andy
Andy

Reputation: 8908

How should I set up a development environment with Docker for WordPress themes?

Little disclaimer before I start: I am a Docker newbie.

My question is mostly stated as above, with a little bit more to my requirements:

docker-compose.yml:

version: '3.1'

services:
  wp:
    image: wordpress
    restart: always
    ports:
      - 48080:80
    links:
      - db:mysql
    volumes:
      - themes:/var/www/html/wp-content/themes
    environment:
      WORDPRESS_DB_PASSWORD: example

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

volumes:
  themes:

Any tips for moving forward?

Upvotes: 0

Views: 58

Answers (1)

sy__
sy__

Reputation: 43

The theme volume did not work on my machine. If I run docker-compose up I get the following error: enter image description here This worked for me on Ubuntu 18.04:

version: '3.1'

services:
  wp:
    image: wordpress
    restart: always
    ports:
      - 48080:80
    links:
      - db:mysql
    volumes:
      - ./themes:/var/www/html/wp-content/themes
    environment:
      WORDPRESS_DB_PASSWORD: example

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

Everything else looks quite good, only improvement for now would be hosting your WordPress on your local file system:

That would give you the possibility to debug WordPress easily and you have full control over the stack.

Downside: User permission can be a problem with Docker. Normally every process inside the container will be executed as root. If WordPress writes a file it has root permissions even on you local file system.

Upvotes: 1

Related Questions