- based on chialab PHP image https://github.com/chialab/docker-php
- support for SSL
- added mariadb-client for mysql and mysqldump binary
- www-data with home path for certificates
- user and group of www-data are re-created with host’s userID and groupID as workaround to file permission issues on the host (userID and groupID are set via —build-arg parameter)
- mhsendmail as sendmail for using Mailhog https://github.com/mailhog/MailHog
Replace USER_ID and GROUP_ID with your host IDs and the TAG you want to create from, and the set the name of the resulting image.
$ sudo docker build --build-arg USER_ID=<you-user-id-on-host> --build-arg GROUP_ID=<your-group-id-on-host> --build-arg TAG=<php-apache-version> -t <you-image-name-here> .
Building an image based on chialab/php from the tag 8.0-apache. The resulting image is named sctp-php:8.0
$ sudo docker build --build-arg USER_ID=1000 --build-arg GROUP_ID=1000 --build-arg TAG=8.0-apache -t scto-php:8.0 .
Docker can make use environment variables in the .env file.
web:
image: "webapp:${TAG}"
If you pass the .env file in the service section in docker-compose.yml it will be passed to the environment of the docker container.
.env
USER=my-user-name
PASS=my-password
docker-compose.yml
version: '3.7'
services: php_apache: image: scto-php:7.4 volumes: - ./public_html/:/var/www/html/ ports: - 80:80 - 443:443 env_file: - .env
And in PHP you can make use of the getenv()
function
<?php
echo getenv('USER'); echo getenv('PASS');