Exploring docker by creating custom php-cli image including many extensions and their required dependencies, and mapping the container user UID with the host UID to make shared files (via volumes) accessibles. The container is running as a non-root (www-data user).
This php-cli image includes all the following extensions (installed and enabled).
Extension | README |
---|---|
Redis | Github Repository |
Memcached | Github Repository |
Apcu | PHP Manual |
Mcrypt | PHP Manual |
Iconv | PHP Manual |
Mbstring | PHP Manual |
Mysqli | PHP Manual |
Pdo_mysql | PHP Manual |
Sockets | PHP Manual |
Zip | PHP Manual |
Pcntl | PHP Manual |
Ftp | PHP Manual |
Bcmath | PHP Manual |
Intl | PHP Manual |
Gettext | PHP Manual |
And many others, you can discover them by yourself 👀 |
In addition of the above extension , this php-cli image includes Composer and PhpUnit as well, installed globally, and such as wget, vim, git, unzip ...
This php-cli is not using the default php configs, instead it is relaying on some custom configurations found inside the folder /usr/local/etc/php/, specifcally php.ini file and the enabled modules inside the folder conf.d, in which only opache module (opache.ini) has custom configurations. feel free to update those configs as per your need. the container is running under www-data user with UID mapped to the host local user's UID
By default, the Docker will expose ports 8080/tcp for the php local server, so change this within the Dockerfile if necessary. When ready, simply use the Dockerfile to build the image.
Clone this repository and follow the simple steps:
# clone
$ git clone git@github.com:khalid-el-masnaoui/docker-php-cli-exploring.git
#cd into the working diretcory
$ cd docker-php-cli-exploring
#image build
$ docker build . -t cs-php-cli -f Dockerfile --build-arg="UID=$(id -u)" --build-arg="GID=$(id -g)"
This will create the custom php-cli image and pull-in/install the necessary dependencies and extensions.
Once done, run the Docker image and map the port to whatever you wish on your host. In this example, we simply map port 8080 of the host to port 8080 of the Docker (or whatever port was exposed in the Dockerfile):
#running the container container
$ docker run -itd --rm -p 8080:8080 --name php-cli --mount type=bind,source=./src/,destination=/dockerBuild/ --mount type=bind,source=./logs/,destination=/var/log/php/ cs-php-cli
#the mounts are for developement purposes -- composer install command inside dockerfile wont take effect if the src/ folder mount is specified -- which (the command) is not needed during the developement
Verify the deployment by navigating to your server address in your preferred browser.
127.0.0.1:8080
The above url will open a page displaying all PHP information. check all extensions are enabled such as opcache , apcu , jit ...