Home Explore Blog CI



docker

1st chunk of `content/guides/php/containerize.md`
0dd281db48362cce28787406127a5e5ffc0aa0b0483674490000000100000809
---
title: Containerize a PHP application
linkTitle: Containerize your app
weight: 10
keywords: php, containerize, initialize, apache, composer
description: Learn how to containerize a PHP application.
aliases:
  - /language/php/containerize/
  - /guides/language/php/containerize/
---

## Prerequisites

- You have installed the latest version of [Docker
  Desktop](/get-started/get-docker.md).
- You have a [git client](https://git-scm.com/downloads). The examples in this
  section use a command-line based git client, but you can use any client.

## Overview

This section walks you through containerizing and running a PHP
application.

## Get the sample applications

In this guide, you will use a pre-built PHP application. The application uses Composer for library dependency management. You'll serve the application via an Apache web server.

Open a terminal, change directory to a directory that you want to work in, and
run the following command to clone the repository.

```console
$ git clone https://github.com/docker/docker-php-sample
```

The sample application is a basic hello world application and an application that increments a counter in a database. In addition, the application uses PHPUnit for testing.

## Initialize Docker assets

Now that you have an application, you can use `docker init` to create the
necessary Docker assets to containerize your application. Inside the
`docker-php-sample` directory, run the `docker init` command in a terminal.
`docker init` provides some default configuration, but you'll need to answer a
few questions about your application. For example, this application uses PHP
version 8.2. Refer to the following `docker init` example and use the same
answers for your prompts.

```console
$ docker init
Welcome to the Docker Init CLI!

This utility will walk you through creating the following files with sensible defaults for your project:
  - .dockerignore
  - Dockerfile
  - compose.yaml
  - README.Docker.md

Let's get started!

? What application platform does your project use? PHP with Apache

Title: Containerizing a PHP Application: Prerequisites, Overview, and Initialization
Summary
This section guides you through containerizing a PHP application using Docker. It outlines the prerequisites, such as having Docker Desktop and a git client installed. It uses a pre-built PHP application with Composer for dependency management and Apache as the web server. The process involves cloning a sample application from GitHub and using `docker init` to generate Docker assets, answering prompts about the application's configuration like the PHP version.