Dev & EngARTICLE

Docker image. To run PHP projects in less than 30 seconds

This week, we released version 8.5 of our Docker image for PHP applications, now with PHP 8.5, and in this post we'll talk a bit about the version and how to use it...

Docker image. To run PHP projects in less than 30 seconds
Image: Leonardo Lemos

This week, we released version 8.5 of our Docker image for PHP applications, now with PHP 8.5, and in this post we will talk a bit about this version and how to use this image.

At Convenia, Brazil's largest HR Tech company, we use this image in a standardized way across all our projects. This means that any developer on the team knows exactly how to start, test and deploy applications without environment surprises, whether in development, staging, or production. In another post we cover all the advantages of standardizing the way applications run

This image has been available since 8.1, being extensively tested and used in production across hundreds of Convenia's projects and pipelines, and has already accumulated more than 10K pulls on Docker Hub.


What is the PHP Full Docker image?

The PHP Full Docker image is a containerized environment that already includes everything PHP applications need to run securely and with good performance:

  • PHP pre-configured with modern versions
  • Integrated web server
  • Useful tools such as Composer, cron, and common extensions
  • Verification tests and regular checks

Convenia has maintained this standard across several versions (from PHP 8.1 to the new 8.5), ensuring stability and continuous support for all the company's projects.


How to use the image

Installation

To get started with Convenia's PHP Full image, just use Docker or Docker Compose.

Using Docker

docker run --rm -p 80:80 convenia/php-full:8.5

When you access your localhost, you'll be able to see documentation similar to this

Documentation of the image being served by the running image itself


This page is the image's own documentation, served by PHP + nginx. In the next docker compose example, we'll see how to run our application inside the image, which is simply mounting a volume or copying an application into the /var/www/app directory inside the container.

Using with Docker Compose

Create a docker-compose.yml file at the root of your project:

services:
  app:
    image: convenia/php-full:8.5
    container_name: app
    volumes:
      - .:/var/www/app
    ports:
      - "80:80"

Then, run:

docker-compose up -d

This file can be placed at the root of a Laravel project, for example, and when you bring up the compose stack, the project should run without major issues.

In fact, this file can be placed in any PHP application that uses the public folder as the request entry point, such as Symfony or Laravel applications. If the entry point is not the root, just point to the public folder when mounting the volume:

    volumes:
      - .:/var/www/app/public

Automatic updates

The image is built and updated weekly to ensure the use of secure versions free of known vulnerabilities, with continuous dependency scanning. The latest build can be checked in the Github Actions workflow


Security

  • The FPM service (port 9000) is exposed only internally within the container
  • It is recommended to block port 9000 in external environments
  • The image already comes with the recommended security settings for production, such as disabling error messages and similar options.

Customization examples

Replacing the Nginx configuration

You can replace the web server's default configuration:

services:
  app:
    image: convenia/php-full:8.5
    volumes:
      - ./nginx.conf:/etc/nginx/http.d/default.conf

This way, you adapt the container to your project's specific rules.


scheduled tasks with cron

The image already includes the cron binary, making scheduled tasks easier:

  1. Add a crontab file with the desired commands;
  2. Copy it to the container:
COPY crontab /etc/crontabs/root
  1. Start cron in the container:
docker run --rm mycronimage crond -l 2 -f

This makes it easier to run commands such as Laravel's scheduler.


Conclusion

Here's a short list of the advantages of using this image in PHP projects:

  • Consistency across environments
  • Ease of use
  • Continuous updates
  • A single standard for the whole company

Translated from the Brazilian Portuguese original · Read the original