title: Docker - executing mkdir, chown & chgrp after the container is up
body: <p>I'm trying to create a docker container, using docker-compose, which mounts a volume on the local filesystem (for the container's /var/www/html) then adds a directory called maps and chowns and chmods is to www-data, so that the web server can write files into it.</p>
  
  <p>I've tried a couple of approaches, using an entrypoint.sh script like this:</p>
  
  <p>Dockerfile</p>
  
  <pre><code>FROM php:5.6-apache
  COPY apache-config.conf /etc/apache2/sites-enabled/000-default.conf
  RUN a2enmod rewrite headers
  RUN service apache2 restart
  COPY entrypoint.sh /entrypoint.sh
  RUN chmod 0755 /entrypoint.sh
  </code></pre>
  
  <p>docker-compose.yml (stuff in {} just comes from a .env file)</p>
  
  <pre><code>version: '2'
  
  services:
    webserver:
      build: ./docker/webserver
      image: web
      ports:
        - "8080:80"
      volumes:
        - ./web:${APACHE_DOC_ROOT}
      links:
        - db
      environment:
        - HTTP_ROOT=http://${DOCKER_HOST_IP}:${DOCKER_HOST_PORT}/
        - PHP_TMP_DIR=${PHP_TMP_DIR}
        - APACHE_LOG_DIR=${APACHE_LOG_DIR}
        - APACHE_DOC_ROOT=${APACHE_DOC_ROOT}/
        - SERVER_ADMIN_EMAIL=${SERVER_ADMIN_EMAIL}
        - MYSQL_USER=${MYSQL_USER}
        - MYSQL_PASSWORD=${MYSQL_PASSWORD}
        - MYSQL_DATABASE=${MYSQL_DATABASE}
  </code></pre>
  
  <p>entrypoint.sh</p>
  
  <pre><code>#!/bin/sh
  
  mkdir /var/www/html/maps
  chown www-data /var/www/html/maps
  chgrp www-data /var/www/html/maps
  exec "$@"
  </code></pre>
  
  <p>I've also tried without any of the entrypoint.sh stuff, just adding this into the composer.yml (after the environment key):</p>
  
  <pre><code>    command: bash -c "mkdir /var/www/html/maps &amp;&amp; chown www-data /var/www/html/maps &amp;&amp; chgrp www-data /var/www/html/maps"
  </code></pre>
  
  <p>But both these approaches seem to give no error in docker-compose logs other than</p>
  
  <blockquote>
    <p>webserver_1 exited with code 0</p>
  </blockquote>