Setup DEV environment with Docker for PHP/PostgreSQL project

Steps listed below are specific to PHP / PostgreSQL project which also needs memcached. That is not ideal flow because each component should be run separately and run using Docker Compose however that is my first attempt to summarize steps I have performed to make it work.

In order to run PostgreSQL db server run the following command:

This will start server at port 5432. Default credentials will be postgres/password. «projectname-db» is container’s name — you may change this to anything else more specific to your project or application.

You may also run apache server with php using the similar command

But in most cases you will probably need to install extra extensions first. So let’s remove that test container by running the following command:

Then create folder for your own configuration and create Dockerfile there

Add the following content to Dockerfile:

Save Dockerfile and run the following command to build image based on the created configuration:

After that you should be able to run Docker container using new image that has been created.

To make sure that your image has been created you may execute the following command:

Before running container you will need to get path to your project so that you can mount that to container right away. To run the container proceed with the following:

That command will launch container and will mount your local ~/projects/testproject folder to the container (and will make ~/projects/testproject/web your DirectoryRoot for apache).

To make sure your container is up and running you may run the following command:

P.S. Dockerfile listed above is intended to be used when you need postgres,apc,curl and memcached modules for php and you have /web folder under your project directory which is used as DocumentRoot (that is default structure for Symfony based applications)


Читайте также: