Docker build: mkdir creates folders, but they disappear in runtime
<p>I'm trying to extend an Apache 2 Docker container with the following Dockerfile:</p>

<pre><code>FROM joomla:3-apache-php7    
RUN apt-get update
RUN a2enmod ssl

RUN printf "\nIncludeOptional /data/apache/conf-enabled/*.conf\n" &gt;&gt; /etc/apache2/apache2.conf
RUN printf "include_path = '.:/data/php/conf.d'" &gt; /usr/local/etc/php/conf.d/additional.ini

RUN bash -c 'mkdir -pv /data/{apache/conf-enabled,php/conf.d}'
RUN ln -s /etc/apache2/sites-enabled/ /data/apache/sites-enabled

VOLUME ["/var/www/html/", "/data/apache/", "/data/php/"]

EXPOSE 80 443

ENTRYPOINT ["/entrypoint.sh"]
CMD ["apache2-foreground"]
</code></pre>

<p>When I try to start the container, this appears:</p>

<pre><code>root@n06 / # docker-compose up -d
root@n06 / # docker-compose logs container
apache2: Syntax error on line 223 of /etc/apache2/apache2.conf: Could not open config directory /data/apache/conf-enabled: No such file or directory
</code></pre>

<p>When I comment out <code>RUN printf "\nIncludeOptional /data/apache/conf-enabled/*.conf\n" &gt;&gt; /etc/apache2/apache2.conf</code> and log into the running container:</p>

<pre><code>root@1c72507b2024:/# ls -la /data/**
/data/apache:
total 8
drwxr-xr-x 2 root root 4096 Sep  3 11:39 .
drwxr-xr-x 5 root root 4096 Sep  3 11:50 ..

/data/php:
total 8
drwxr-xr-x 2 root root 4096 Sep  3 11:39 .
drwxr-xr-x 5 root root 4096 Sep  3 11:50 ..
</code></pre>

<p>The created dirs disappear randomly, sometimes the /data/apache/conf-enabled directory is there.</p>

<h2>Edit</h2>

<pre><code>docker-compose.yml:

version: '2'

networks:
  main:
    driver: bridge
    ipam:
       driver: default
       config:
         - subnet: 172.18.0.0/16
           gateway: 172.18.0.1

services:
  test:
    build: docker/test
    container_name: test
    networks:
      - main
    volumes:
      - /mnt/docker/test/joomla:/var/www/html
      - /mnt/docker/test/apache:/data/apache/
      - /mnt/docker/test/php:/data/php/
      - /etc/letsencrypt:/etc/letsencrypt
      - /var/lib/letsencrypt:/var/lib/letsencrypt
      - /etc/localtime:/etc/localtime
    links:
      - mariadb:mariadb
    environment:
      - JOOMLA_DB_USER=test
      - JOOMLA_DB_PASSWORD=test
      - JOOMLA_DB_HOST=mariadb
      - JOOMLA_DB_NAME=test
</code></pre>