Skip to content

EdoFede/nginx-php-fpm-Docker

Repository files navigation

Docker nginx & PHP-FPM base image

A base image with nginx web server and PHP-FPM.


Build Status Codacy Badge

Introduction

This Docker image is based top of my Alpine base image and it's basically a ready-to-run nginx + PHP-FPM web server.

Multi-Architecture

This image is built with multiple CPU architecture support.
As stated in Docker best-practice, the image is tagged and released with current version tag for many cpu architectures and a manifest "general" version tag, which automatically points to the right architecture when you use the image.

I also add the "latest" manifest tag every time I release a new version.

How to use

Use as base image

The image is available on the Docker hub and can be used as base image to build your own Web project or Web-app.

FROM edofede/nginx-php-fpm:<VERSION>

Container creation

You can simply create and start a Docker container from the image on the Docker hub

Dynamically publish HTTP port

If you want to test the container and don't care about HTTP port mapping, you can use dynamic mapping:

docker create \
	--name nginx-php-fpm --publish-all \
	edofede/nginx-php-fpm:latest
docker start nginx-php-fpm

Then get the assigned port on the host with:

docker port nginx-php-fpm 80/tcp

Statically publish HTTP port

If, instead, you want to map a specific port to the host, you can use static mapping:

docker create \
	--name nginx-php-fpm --publish <host port>:80/tcp \
	edofede/nginx-php-fpm:latest
docker start nginx-php-fpm

Container local access

After the container is started, you can launch bash or other commands inside:

docker exec -ti nginx-php-fpm bash

If, instead, you want to run the image one-shot, without starting Web services, use:

docker run -ti --rm edofede/nginx-php-fpm:latest bash

Entrypoint

The entrypoint script (/entrypoint.sh) accepts arguments. These are launched on the container, instead of starting runit and related services (nginx and PHP-FPM are not started if you pass arguments via the entrypoint).

Setup

Default configuration

I've included a basic configuration that works for general needs. If you need particular setup, you can put nginx/PHP-FPM config files on a persisten volume and make your own setup.

Data volume

The web server uses by default the /var/www/ directory as root folder, but I've not created a Volume mapping in the Dockerfile, to leave freedom of choice.
If you plan to use this image as a base image to develop your Webapp, you can simply declare the Volume for data persistance in your Dockerfile.

Test files

Three test files are present inside /var/www/ folder. You can safely delete it, since are used just for automated test during deploy.

Set timezone

The image comes with tzdata already installed (and timzone setted to Europe/Rome). To set a new timezone, launch a bash command and follow this guide (skip the first command).

Support me

I treat these free projects exactly like professional works and I'm glad to share it, with some of my knowledge, for free.

If you found my work useful and want to support me, you can donate me a little amount
Donate