skip to Main Content

I created a docker-compose.yml file with the code below :

version: "3.8"
services:

  db:
    image: mysql:latest
    command: --default-authentication-plugin=mysql_native_password
    container_name: docker_database
    restart: always
    volumes:
      - db-data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
    networks:
      - dev

  phpmyadmin:
    image: phpmyadmin:latest
    container_name: docker_phpmyadmin
    restart: always
    depends_on:
      - db
    ports:
      - 8081:80
    environment:
      PMA_HOST: db
    networks:
      - dev

  prestashop:
    build: php
    container_name: docker_prestashop
    ports:
      - 8080:80
    volumes:
      - ./php/vhosts:/etc/apache2/sites-enabled
      - ./:/var/www/html
    restart: always
    networks:
      - dev

networks:
  dev:

volumes:
  db-data:

And also this Dockerfile :

FROM php:7.4-apache

RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf

RUN apt-get update 
    && apt-get install -y --no-install-recommends locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev;

RUN echo "en_US.UTF8 UTF8" > /etc/locale.gen && 
    echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && 
    locale-gen

RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && 
    mv composer.phar /usr/local/bin/composer

RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo pdo_mysql gd opcache intl zip calendar dom mbstring zip gd xsl
RUN pecl install apcu && docker-php-ext-enable apcu
RUN a2enmod rewrite && service apache2 restart

The goal is to create a prestashop environnement however I’m struggling with a Error 500 when trying to install the prestashop. I’ve read that it has something to do with file permissions. Some of the folders are accessible but I don’t know why some of them like the config folder is in read-only. I’ve created a volume that I share with container and host but I think I did something wrong on the configuration.
Even when I run a chmod 770 <some-file> I can access it but when I’m trying to change something in it I get this error :

Cannot save /home/benju/Bureau/docker/config/defines.inc.php.
Unable to create a backup file (defines.inc.php~).
The file left unchanged.

How could I access them with the same permission as the container on the host computer ?

2

Answers


  1. Chosen as BEST ANSWER

    Here is what I've done and it worked (not sure if this is a good practice)

    chown -R <hostuser>:<hostuser> <project root>
    

  2. You could use the use the same user and group with the docker run parameter, --user "$(id -u):$(id -g)"

    with this the container can still give you an error, while bash on the container won’t, but other applications can, because the user and group need to be created, so in the docker file,

    ARG USER_ID
    ARG GROUP_ID
    
    RUN addgroup --gid $GROUP_ID user
    RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID user
    USER user
    

    Then the file permissions which would be set by the container will on the volume will be the same as the host setting the file permissions.

    More information on the following webpage,
    https://vsupalov.com/docker-shared-permissions/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search