0
votes

I am using puppet docker (https://forge.puppet.com/modules/puppetlabs/docker) and setup PHP-Apache website using PHP docker image (https://hub.docker.com/layers/php/library/php/7.2.34-apache/images/sha256-77e5a326252f951aa557f48829973f67e8efde9c52f81ee4e4a5473a59a217d9?context=explore)

The PHP script works fine but when I added .htaccess file in folder, it is throwing error

[Mon Jan 25 09:52:12.078604 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.2.34 configured -- resuming normal operations
[Mon Jan 25 09:52:12.078766 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
[Mon Jan 25 09:52:32.734378 2021] [autoindex:error] [pid 16] [client 172.17.0.1:50756] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
172.17.0.1 - - [25/Jan/2021:09:52:32 +0000] "GET / HTTP/1.1" 403 493 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0"
172.17.0.1 - - [25/Jan/2021:09:52:32 +0000] "GET /favicon.ico HTTP/1.1" 404 489 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0"
[Mon Jan 25 09:56:33.265445 2021] [autoindex:error] [pid 18] [client 172.17.0.1:50830] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
172.17.0.1 - - [25/Jan/2021:09:56:33 +0000] "GET / HTTP/1.1" 403 493 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0"
[Mon Jan 25 09:56:52.186711 2021] [core:alert] [pid 17] [client 172.17.0.1:50854] /var/www/html/packageContent/.htaccess: Invalid command 'RewriteRule', perhaps misspelled or defined by a module not included in the server configuration

I believe I need to RUN a2enmod rewrite as in here (https://stackoverflow.com/a/38064289/376702)

I don't know how can I set up using puppet docker(https://forge.puppet.com/modules/puppetlabs/docker).

Can anyone please guide me? Here is my puppet code.

 docker::image { 'docker.io/php':
    image_tag => '7.2.34-apache'
  }

  docker::run { 'test123.com':
    image            => 'docker.io/php:7.2.34-apache',
    command          => 'apache2-foreground',
    expose           => ['80'],
    ports            => ['8101:80'],
    volumes          => ['/var/www/test123.com:/var/www/html'],
    hostname         => 'test123.com',
    restart_service  => true,
    before_stop      => 'echo "So Long, and Thanks for All the Fish"',
    before_start     => 'echo "Run this on the host before starting the Docker container"',
    after_stop       => 'echo "container has stopped"',
    after_start      => 'echo "container has started"',
    extra_parameters => [ '--restart=always' ],
  }

I am running docker in Linux RedHat

Ref: .htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

1
If you need to RUN a2enmod rewrite in the Dockerfile, then that would likely be most achieveable in a multi-stage build, and you can manage the resulting image from the new Dockerfile in Puppet. Modifying the Dockerfile of an image from the official repository is likely not possible in Puppet (or otherwise) without extensive additional coding.Matt Schuchard

1 Answers

0
votes

I rebuild PHP apache official image with the following configuration

# Dockerfile

FROM docker.io/php:7.2.34-apache
RUN a2enmod rewrite

puppet code changes in pp puppet class

      docker::image { 'php-apache7234':
        docker_file => '/tmp/Dockerfile',
        subscribe   => File['/tmp/Dockerfile'],
      }
    
      file { '/tmp/Dockerfile':
        ensure => file,
        source => 'puppet:///modules/mydocker/php_apache/Dockerfile',
      }

  docker::run { 'test123.com':
    image            => 'php-apache7234',
    command          => 'apache2-foreground',
    expose           => ['80'],
    ports            => ['8101:80'],
    volumes          => ['/var/www/test123.com:/var/www/html'],
    hostname         => 'test123.com',
    restart_service  => true,
    before_stop      => 'echo "So Long, and Thanks for All the Fish"',
    before_start     => 'echo "Run this on the host before starting the Docker container"',
    after_stop       => 'echo "container has stopped"',
    after_start      => 'echo "container has started"',
    extra_parameters => [ '--restart=always' ],
  }