-1

I dockerized my application, so I sent my files in the image with the COPY command in dockerfile

Here my dockerfile

FROM wordpress:php7.4-apache
COPY ./site /var/www/html
RUN chmod -R 777 /var/www/html/wp-content
ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0"

When I use the image with docker-compose and when I link the volume with my local directory I do not recover the files I had sent during the creation of the image

Here my docker-compose.yml file

version: "3.8"

services:
  ict:
    image: name_of_my_new_image
    volumes:
      - .:/var/www/html
    ports:
      - 80:80
    restart: always

Anyone have a solution please?

  • A volume mount always hides the contents of the image. So if you do something like `COPY igAWB.png ./assets/` to include the PNG file from the question in your image, and then mount something else over the container's `assets` directory, you won't see the image's file. Can you [edit] the question to include the actual Dockerfile (and not a PNG file) and the `docker-compose.yml` file? – David Maze Nov 09 '22 at 11:11
  • @David I just edited it. If I don't mount a volume and if I look in the container directly I can see my files fine. And then if I mount the volume, I don't recover the files and they are no longer in the container – Andriantseheno Nov 09 '22 at 12:47
  • That's consistent with the way mounting in Unix works in general: mounting anything over a directory hides the content that was already there. – David Maze Nov 09 '22 at 14:16
  • [Docker mount to folder overriding content](https://stackoverflow.com/questions/47664107/docker-mount-to-folder-overriding-content) asks a similar question, though more about config files. I'd avoid using `volumes:` to hide the code or assets built into an image. – David Maze Nov 09 '22 at 14:18

1 Answers1

-1

Try something like this

version: '2'

    services:
       wordpress:
         depends_on:
           - db
         image: wordpress:5.5.0-php7.2-apache
         ports:
           - "8080:80"
         restart: always
         environment:
           WORDPRESS_DB_HOST: db:3306
           WORDPRESS_DB_PASSWORD: P@ssw0rdjbc83
         volumes: 
           - /tmp/wordpress.ini:/usr/local/etc/php/conf.d/wordpress.ini 
    volumes:
        db_data:

Which file you want to mount? I used ini to set my PHP option values.

Richard Rublev
  • 7,718
  • 16
  • 77
  • 121
  • I don't directly use the wordpress image but the image I just created with the dockerfile by sending my files in it, it's these same files that I would like to mount but I can't – Andriantseheno Nov 09 '22 at 08:06
  • @Andriantseheno It will pull image if it can not find it ,no need to worry about that. – Richard Rublev Nov 09 '22 at 08:53
  • My problem is that I recover the wordpress files well but not the files that I copied in the image. Can be a permission problem or I don't know what – Andriantseheno Nov 09 '22 at 12:52
  • @Andriantseheno Take a look at my example volumes line. What actaully you want to mount? Which folder? It will apprear in you container. – Richard Rublev Nov 09 '22 at 13:00
  • I just edited the post and put the code from docker-compose. I would like to mount the /var/www/html volume. If I use the wordpress image from the hub directly, I recover all these files, but if I use the image I just created, I do not recover any files. – Andriantseheno Nov 09 '22 at 13:59