6

I have a Wordpress container that I would like to copy local folders (with files) to at startup

I have local files in folders:

/html/wp-content/plugins
/html/wp-content/themes
/html/wp-content/uploads

I have a Dockerfile with:

FROM wordpress

COPY ./html/wp-content/plugins/ /var/www/html/wp-content/plugins
COPY ./html/wp-content/themes/ /var/www/html/wp-content/themes
COPY ./html/wp-content/uploads/ /var/www/html/wp-content/uploads

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]

Although the COPY is succeeding (the build passes), the files are not showing up in these destination folders.

If I change the destination folders to be on any path before /html, eg if I put the destination to be /var or /var/www, then the files copy and I can see them in the container.

I checked out this old post here, which mentions that the /html folder is actually mounted as a volume at startup, and so I need to copy the files into this folder first

/usr/src/wordpress/wp-content

and then at startup these folders will be automatically copied across to /var/www/html/wp-content/. (This would explain why copying directly does not seem to work)

I tried that too, and while my local folders are indeed copied into these folders (I can see them in the container), they are then not copied across to /var/www/html/content at startup!

  1. Is it possible to copy the local files directly into the /var/www/html folders via the dockerfile?
  2. If not, how can I ensure that if copying to /usr/src/wordpress/wp-content, the folders will be copied across to /var/www/html/wp-content/ at startup?

(Some posts I've looked through that don't work, as this seems to be particular to Wordpress, and not Dockerfile COPY on its own:)

Dockerfile copy keep subdirectory structure Docker is not copying subdirectory into Container How to copy folders to docker image from Dockerfile? https://www.serverlab.ca/tutorials/containers/docker/how-to-host-your-wordpress-site-with-docker/ Wordpress docker copy theme into exposed folder

leo_cape
  • 141
  • 3
  • 14
  • 1
    [Ronald Johnson](https://stackoverflow.com/users/7628376/ronald-johnson) posted an [Answer](https://stackoverflow.com/a/65235658/12695027) saying "..a misplaced or not placed '/' at the end of a path in apache2.conf or other config file" – Scratte Dec 10 '20 at 21:07
  • 1
    Did you find a solution regarding this and can share? Having same issue myself! – Flamur Mavraj Jun 27 '21 at 02:27
  • @FlamurMavraj in the end I changed direction and used a mounted volume instead, which helped slightly with the deployment pipeline. But still unable to find a silver bullet pipeline for wordpress - so I still have to make some changes to production on production itself which isnt great. – leo_cape Jul 20 '21 at 12:52
  • @Scratte the answer must have been deleted, but from what you're saying I dont think that was the problem.. – leo_cape Jul 20 '21 at 12:53
  • @leo_cape Yes, it was deleted. I came across it when reviewing. I didn't know if it would be useful or not, so I put the content in a comment. I can remove the comment, if you like. – Scratte Jul 20 '21 at 13:22

1 Answers1

0

Today I ran into the same problem. I wanted to add theme when building the image by using COPY. However, it did not work. This was because I already set my wp-content folder as a volume. It seems you cannot COPY into a volume.

The discussion in the following link helped me realise this:

https://github.com/docker-library/wordpress/issues/146

Below I have added my WordPres Dockerfile and docker-compose file. After commenting out the volume everything worked as expected.

I sure hope you do not need it anymore after two years, haha.

Reference: https://docs.docker.com/samples/wordpress/

Dockerfile

FROM wordpress:latest

WORKDIR /var/www/html

COPY ./wp-content/ ./wp-content/
RUN chmod -R 755 ./wp-content/


docker-compose.yml

version: "3"
services:
  db:
    build:
      context: .
      dockerfile: ./compose/local/db/Dockerfile
    image: new_db_image_name
    container_name: new_db_image_name
    command: '--default-authentication-plugin=mysql_native_password'
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=somewordpress
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=wordpress
    expose:
      - 3306
      - 33060
  wordpress:
    build:
      context: .
      dockerfile: ./compose/local/wordpress/Dockerfile
    image: new_wordpress_image_name
    container_name: new_wordpress_image_name
#    volumes:
#      - wp-content:/var/www/html/wp-content
    ports:
      - 80:80
    restart: always
    environment:
      - WORDPRESS_DB_HOST=db
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=wordpress
      - WORDPRESS_DB_NAME=wordpress

volumes:
  db_data:
#  wp-content: