php-fpm and nginx with mysqli, gd, freetype, jpeg, mcrypt, ssl, flv, mp4 and more
1.4K
Run nginx and php-fpm in your development environment in minutes!
This docker image includes nginx v1.19.4 and php-fpm v7.4 configured to support mysqli, gd (with freetype and jpeg), mcrypt, ssl, flv, mp4 and more. Nginx is compiled from the source code, so you can easily add additional modules. php-fpm loads modules via docker-php-ext-* so you can add additional modules to it too. It is also preconfigured to pseudostrem mp4 and flv files (see http://nginx.org/en/docs/http/ngx_http_mp4_module.html) and supports uploading large files (up to 100Mb).
You can skip these environment variables and specify the paths directly in the docker run command, I added them just to make it easier to keep things in one place
NGINX_PHP_BASE_DIR=/docker_data/nginxphp - this is where you want to keep all system files including the configuration,
and the logsNGINX_PHP_WWW_DIR=/docker_data/www - this is where you plan to keep the web server contentdocker run -d --restart=unless-stopped --name nginxphp -v ${NGINX_PHP_BASE_DIR}/nginx_etc:/etc/nginx -v ${NGINX_PHP_BASE_DIR}/nginx_log:/var/log/nginx -v ${NGINX_PHP_BASE_DIR}/php_log:/var/log/php-fpm -v ${NGINX_PHP_WWW_DIR}:/www -p 8080:80 rtfms/nginx-php
Let's see what's in this docker command:
docker run - means "start the docker container from the image"-d - will run it in the background, so this command won't block your terminal--restart=unless-stopped - if you will restart Docker (or your server/computer) this will restart the container when
the docker daemon will start again--name nginxphp - gives a name to the docker container, makes it easier to manage it once it's running-v ${NGINX_PHP_BASE_DIR}/nginx_etc:/etc/nginx - this will persist nginx configuration files in ${NGINX_PHP_BASE_DIR}/nginx_etc.
This and the rest of the -v HOST_DIR:CONTAINER_DIR configuration parameters map directories from your computer to the
container's file system so that the files in these directories could persist between the container restarts. If you do
not want to persist the logs and totally fine with the default ocnfiguration files then you can omit most of the -v ...
options.-v ${NGINX_PHP_BASE_DIR}/nginx_log:/var/log/nginx - this is where nginx logs will be saved-v ${NGINX_PHP_BASE_DIR}/php_log:/var/log/php-fpm - where to keep php logs-v ${NGINX_PHP_WWW_DIR}:/www - location of the web server content. This is likely the one -v option that you will want to keep,
otherwise the container will keep serving the default nginx page.-p 8080:80 - this tells docker to map the web server to port 8080. You can change this to whatever port you needrtfms/nginx-php - this is the name of the docker imagedocker exec -it nginxphp bashkillall -USR2 php-fpm and make it reload the configs.nginx -t and fix the errors if anykillall -HUP nginx to make it reload the configuration files.docker build -t nginx-php .You can, with the proper security measures (like configuring the filrewall, LIDS, antivirus etc) and after providing appropriate configuration files. However, this image is more optimized specifically for development. It includes certain tools (compilers, network utilities, editors etc) that make developing the web server configuration easier, but also make the image bloated and, thus, less secure. So whether to use this image in the production or not depends on your specific goals.
I hope that this image could be a good foundation for the production config after you edit the Docker file, and the config files to meet your specific configuration and security needs and then remove all unnecessary modules and tools from it by updating the Dockerfile.
Content type
Image
Digest
Size
283.8 MB
Last updated
almost 5 years ago
docker pull rtfms/nginx-php