matomo-org / docker

Official Docker project for Matomo Analytics
https://matomo.org
Other
836 stars 347 forks source link

getting permissions error with docker #199

Open ralyodio opened 4 years ago

ralyodio commented 4 years ago
Matomo couldn't write to some directories (running as user 'www-data').

Try to Execute the following commands on your server, to allow Write access on these directories:

chown -R www-data:www-data /var/www/html
find /var/www/html/tmp -type f -exec chmod 644 {} \;
find /var/www/html/tmp -type d -exec chmod 755 {} \;
find /var/www/html/tmp/assets/ -type f -exec chmod 644 {} \;
find /var/www/html/tmp/assets/ -type d -exec chmod 755 {} \;
find /var/www/html/tmp/cache/ -type f -exec chmod 644 {} \;
find /var/www/html/tmp/cache/ -type d -exec chmod 755 {} \;
find /var/www/html/tmp/logs/ -type f -exec chmod 644 {} \;
find /var/www/html/tmp/logs/ -type d -exec chmod 755 {} \;
find /var/www/html/tmp/tcpdf/ -type f -exec chmod 644 {} \;
find /var/www/html/tmp/tcpdf/ -type d -exec chmod 755 {} \;
find /var/www/html/tmp/templates_c/ -type f -exec chmod 644 {} \;
find /var/www/html/tmp/templates_c/ -type d -exec chmod 755 {} \;
If this doesn't work, you can try to create the directories with your FTP software, and set the CHMOD to 0755 (or 0777 if 0755 is not enough). To do so with your FTP software, right click on the directories then click permissions.

DOcker should be running everything as root so I'm not sure why there are permission issues inside the container.

acountrec commented 4 years ago

I know what you mean, it surprises me that their example code (apache at least) is not working from the get go.

Here is what I recommend: Create a dockerfile like this:

FROM matomo:3.13

RUN chown -R www-data:www-data /var/www/html
RUN find /var/www/html/tmp -type f -exec chmod 644 {} \; || true
RUN find /var/www/html/tmp -type d -exec chmod 755 {} \; || true
RUN find /var/www/html/tmp/assets/ -type f -exec chmod 644 {} \; || true
RUN find /var/www/html/tmp/assets/ -type d -exec chmod 755 {} \; || true
RUN find /var/www/html/tmp/cache/ -type f -exec chmod 644 {} \; || true
RUN find /var/www/html/tmp/cache/ -type d -exec chmod 755 {} \; || true
RUN find /var/www/html/tmp/logs/ -type f -exec chmod 644 {} \; || true
RUN find /var/www/html/tmp/logs/ -type d -exec chmod 755 {} \; || true
RUN find /var/www/html/tmp/tcpdf/ -type f -exec chmod 644 {} \; || true
RUN find /var/www/html/tmp/tcpdf/ -type d -exec chmod 755 {} \; || true
RUN find /var/www/html/tmp/templates_c/ -type f -exec chmod 644 {} \; || true
RUN find /var/www/html/tmp/templates_c/ -type d -exec chmod 755 {} \; || true

You could probably remove most of these RUNs but they dont hurt so I just left them as is.

bhavnapruthi823 commented 3 years ago

above you hvae given basic image as matomo, what if I need PHP apache as base image, than how can i correct these tmp folder errors

EDIflyer commented 2 years ago

I'm getting the same issue here with the latest image... image

docker-compose is as follows (using nginx proxy manager so only exposing port)

version: '3'
services:
  app:
    image: matomo:latest
    restart: unless-stopped
    environment:
      - MATOMO_DATABASE_HOST=db
      - MATOMO_DATABASE_TABLES_PREFIX=mat_
      - MATOMO_DATABASE_USERNAME=matomo-CHANGE
      - MATOMO_DATABASE_PASSWORD=matomo-CHANGE
      - MATOMO_DATABASE_DBNAME=matomo
    volumes:
      - /home/ediflyer/containers/matomo/app:/var/www/html
    links:
      - db:db
    expose:
      - 80/tcp
    networks:
      - nginx-proxy-manager_default         
  db:
    image: yobasystems/alpine-mariadb:latest
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: matomo
      MYSQL_USER: matomo-CHANGE
      MYSQL_PASSWORD: matomo-CHANGE
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - /home/ediflyer/containers/matomo/db:/var/lib/mysql
    networks:
      - nginx-proxy-manager_default
networks:
  nginx-proxy-manager_default:
    external: true
    name: nginx-proxy-manager_default

EDIT - OK so I removed all containers and existing files and recreated the stack & that seemed to do the trick.