I am running WordPress with Nginx in Docker using Docker Compose and I want to copy over a custom theme. Right now in my docker-compose.yml file I have,

  wordpress:
depends_on:
  - db
image: wordpress:5.1.1-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
  - WORDPRESS_DB_HOST=MYHOST
  - WORDPRESS_DB_USER=$MYSQL_USER
  - WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
  - WORDPRESS_DB_NAME=MYDB
volumes:
  - ./plugins/advanced-custom-fields:/var/www/html/wp-content/plugins/advanced-custom-fields
  - ./themes/mytheme:/var/www/html/wp-content/themes/mytheme
It kind of works. The theme copies over some of the php files from the theme folder but it doesn't copy over any of the stylesheets or any of the images in the /img/ folder.

Any ideas?

Thanks in advance!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
3 answers

Hello,

Actually the snippet that you’ve provided looks correct. Have you manually checked if the files are actually there?

You could do that by attaching to the running container with docker exec and listing the contents of the /var/www/html/wp-content/themes/mytheme directory.

To do that you could run the following:

docker ps -a

Find the ID of your container and then run:

docker exec -it your_container_id bash

Then once you are attached run:

ls -l /var/www/html/wp-content/themes/mytheme

If the files are actually there make sure that the permissions are correct.

Then to detach press CTRL+P+Q.

You could also check the logs of the container for any errors:

docker logs your_container_id 

Hope that this helps!
Regards,
Bobby

  • Thanks Bobby! By any chance do you know what permissions it should have and how to set them via Docker Compose?

    Thanks!

    • Hi Justin,

      I believe that for the wordpress:5.1.1-fpm-alpine image the ownership of the files should be set to www-data for both the owner and the group.

      Regards,
      Bobby

      • I have a similar problem but when i check the permissions, the wordpress image does not have a www-data group

        • Hi there @konturgestalter,

          Which is the exact WordPress Docker image that you are using currently? And also what is the exact error that you get?

          Regards,
          Bobby

          • Hi Bobby,
            thank you for your fast response, actually the issue was not the permissions as I found out last night (after 6hrs debugging.......... for no reason…) I created a bind mount to a host folder hosting the wordpress theme in the wordpress service. But i didnt create the same bind in the nginx service, so while wordpress was linked to it, it was not finding anything on the webserver service.

            Then i also wonder why… if I create the bind on the webserver only, shouldn’t the wordpress service it also see it? Both share a volume, but I assume that is independent from what I share via bind, right?

          • Hi there @konturgestalter,

            This is quite interesting. Can you share your exact Docker compose file so that I could have another look as well?

            Regards,
            Bobby

Yep absolutly. Here it is:

version: '3'

services:
  db:
    image: mysql:8.0
    container_name: db
    restart: unless-stopped
    env_file: .env
    environment:
      - MYSQL_DATABASE=wordpress
    volumes: 
      - db_data:/var/lib/mysql
    command: '--default-authentication-plugin=mysql_native_password'
    networks:
      - KGNet

  wordpress:
    depends_on: 
      - db
    image: wordpress:5.4.1-fpm
    container_name: wordpress
    restart: unless-stopped
    env_file: .env
    environment:
      - WORDPRESS_DB_HOST=db:3306
      - WORDPRESS_DB_USER=$MYSQL_USER
      - WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
      - WORDPRESS_DB_NAME=wordpress
    volumes:
      - wp_data:/var/www/html
      - ./wp-content:/var/www/html/wp-content/
    networks:
      - KGNet

  webserver:
    depends_on:
      - wordpress
    image: nginx:1.17.10
    container_name: webserver
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - wp_data:/var/www/html
      - ./wp-content:/var/www/html/wp-content/
      - ./nginx-conf:/etc/nginx/conf.d
      - certbot-etc:/etc/letsencrypt
    networks:
      - KGNet

  certbot:
    depends_on:
      - webserver
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbot-etc:/etc/letsencrypt
      - wp_data:/var/www/html
    command: certonly --webroot --webroot-path=/var/www/html --email sebastianscharf@icloud.com --agree-tos --no-eff-email --staging -d konturgestaltung.de -d www.konturgestaltung.de

volumes:
  certbot-etc:
  wp_data:
  db_data:

networks:
  KGNet:

Seems actually odd to my.. why would i need to add my folder twice? I am fairly new to docker though…

Submit an Answer