Im few days in one project where I have a task of using Docker. After following few tutorials I find the easy way of deploying my LAMP server using docker-compose
that looks like this:
version: '3.7'
services:
php-httpd:
image: php:7.3-apache
ports:
- 80:80
volumes:
- "./DocumentRoot:/var/www/html"
mariadb:
image: mariadb:10.5.2
volumes:
- mariadb-volume:/var/lib/mysql
environment:
TZ: "Europe/Rome"
MYSQL_ALLOW_EMPTY_PASSWORD: "no"
MYSQL_ROOT_PASSWORD: "rootpwd"
MYSQL_USER: 'testuser'
MYSQL_PASSWORD: 'testpassword'
MYSQL_DATABASE: 'testdb'
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- 'mariadb:db'
ports:
- 8081:80
volumes:
mariadb-volume:
Now after my app is in middle of development i find a problem that I need to edit the .htaccess
to turn on mod_rewrite and add some rules for REST API.
All solutions that I find are mentioning that I should add RUN command in dockerfile
similar to this:
FROM httpd:alpine
# Copy .htaccess into DocumentRoot
COPY ./.htaccess /var/www/html/
RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf
But I dont have that file, and offical documentation is of no help for me.
All I do is sudo docker-compose up -d
to run my images. So question is:
In what stage, how and where should I add this file to make it work.
I know is possible cose I find this statement in one tutorial:
Next time around, we’ll create a more complicated docker-compose.yml
file, one that works in conjunction with a Dockerfile.
But there was no followup on this.
I would appreciate any guidance on this.
Also I know I can access PHP image with: docker exec -it linuxconfig_php-httpd_1 bash
.
Maybe I can do something with that?
2
Answers
You have two options:
Dockerfile content
Create Image:
This will create a new image name (custom-php:7.3-apache). You can then use this new image in your docker-compose.yml file and when deployed, the container will have the updated .htaccess
.
I prefer #2 as you can edit .htaccess rules without rebuilding the image.
In Dockerfile add "RUN a2enmod rewrite"