Writable folder permissions in docker

I have a docker setup with some websites for localhost. I use Smarty as my template engine and it requires to have a writable templates_c folder. Any idea how I can make this folder writable?

The error is as following:

  • Import broker definitions into Dockerized RabbitMQ
  • What would prevent code running in a Docker container from connecting to a database on a separate server?
  • distributed wide and deep with tf.contrib.learn api example stuck on k8s
  • syntax error in wercker file when using wercker login command
  • pg_dump server and pg_dump version mismatch in docker
  • How avoid docker0 interface starting?
  • PHP Fatal error:  Smarty error: unable to write to $compile_dir 
    '/var/www/html/sitename.local/httpdocs/templates_c'. 
    Be sure $compile_dir is writable by the web server user. in 
    /var/www/html/sitename.local/httpdocs/libs/Smarty.class.php on 
    line 1093
    

    I know this could be set manually with linux but I am looking for an automatic global solution since I have many websites who have this issue

    Also worth mentioning I am using a pretty clean docker-compose.yml

    php56:
      build: .
      dockerfile: /etc/docker/dockerfile_php_56
      volumes:
        - ./sites:/var/www/html
        - ./etc/php:/usr/local/etc/php
        - ./etc/apache2/apache2.conf:/etc/apache2/conf-enabled/apache2.conf
        - ./etc/apache2/hosts.conf:/etc/apache2/sites-enabled/hosts.conf
      ports:
        - "80:80"
        - "8080:8080"
      links:
        - mysql
    
    
    mysql:
      image: mysql
      ports:
        - "3306:3306"
      environment:
        - MYSQL_ROOT_PASSWORD=MY_PASSWORD
        - MYSQL_DATABASE=YOUR_DATABASE_NAME
      volumes: 
        - ./etc/mysql:/docker-entrypoint-initdb.d
    

    With a small dockerfile for basics:

    FROM php:5.6-apache
    
    RUN /usr/local/bin/docker-php-ext-install mysqli mysql
    RUN    docker-php-ext-configure mysql --with-libdir=lib/x86_64-linux-gnu/ \
        && docker-php-ext-install mysql
    RUN a2enmod rewrite
    

    https://github.com/wesleyd85/docker-php7-httpd-apache2-mysql (but then with php 5.6)

  • Is there a way to combine Docker images into 1 container?
  • How do I run private docker images on Google Container Engine
  • Running multiple applications in one docker container
  • error while loadingDocker: shared libraries: libsystemd-journal.so.0: cannot open shared object file: No such file or directory
  • Equivalent of docker-compose.yml parameters in Docker Cloud
  • Nginx Load Balancing Upstream proxy
  • One Solution collect form web for “Writable folder permissions in docker”

    I solved the same problem with the solution here: Running docker on Ubuntu: mounted host volume is not writable from container

    Just need to add:

    RUN chmod a+rwx -R project-dir/smarty.cache.dir
    

    to Dockerfile

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.