user8325933
user8325933

Reputation:

WordPress image with pre-installed plugins using Dockerfile

Copying plugin folder to WordPress default image directory and creating a new image. Pushing it to the repository on Docker Hub, then pull back image and run the container, but the plugin is not installed. Folder is not found in the container.

docker-compose.yml

version: '3.3'
services:
  wp:
    image: "arslanliaqat/wordpresswithplugin:1.0"
    volumes:
      - './wordpress:/var/www/html'
    ports:
      - "8000:80"
    environment:
      WORDPRESS_DB_PASSWORD: qwerty
  mysql:
    image: "mysql:5.7"
    environment:
      MYSQL_ROOT_PASSWORD: qwerty
    volumes:  
      - "my-datavolume:/var/lib/mysql"
volumes: 
  my-datavolume:

Dockerfile

FROM wordpress:php7.1-apache

COPY preferred-languages /var/www/html/wp-content/plugins/preferred-languages/

could not pre-install plugin

Upvotes: 5

Views: 3212

Answers (1)

Kārlis Ābele
Kārlis Ābele

Reputation: 1021

So this is what's happening:

When you are building your custom image, you add the plugin folder /var/www/html/wp-content/plugins/preferred-languages/ and that works just fine.

You can test that by simply running docker run -it --rm arslanliaqat/wordpresswithplugin sh and cd /var/www/html/wp-content/plugins and you should see the folder.

The reason the folder is missing when you are using your docker-compose.yml file is because you are mounting the volume "over" the folder that's already there. Try removing the volumes declaration from wp service in the docker-compose.yml file and then you should be able to see your plugin folder.

I would suggest you use the wordpress:php7.1-apache for your wp service and mount your plugin folder the same way you are mounting wordpress

Example:

version: '3.3'
services:
  wp:
    image: "wordpress:php7.1-apache"
    volumes:
      - './wordpress:/var/www/html'
      - './preferred-languages:/var/www/html/wp-content/plugins/preferred-languages'
    ports:
      - "8000:80"
    environment:
      WORDPRESS_DB_PASSWORD: qwerty
  mysql:
    image: "mysql:5.7"
    environment:
      MYSQL_ROOT_PASSWORD: qwerty
    volumes:  
      - "my-datavolume:/var/lib/mysql"
volumes: 
  my-datavolume:

Is there a specific reason you need the plugin to be in the image already?


UPDATED

I created a simple gist which should accomplish what you want to do. The entrypoint lacks checks for already existing theme/plugin directories etc, but this should serve as POC

https://gist.github.com/karlisabe/16c0ccc52bdf34bee5f201ac7a0c45f7

Upvotes: 3

Related Questions