/docker-php-development

Docker compose for PHP development

Primary LanguageShell

Viblo Docker for PHP Development

Docker containers for Viblo development.

Requirement

  • Docker version at least 18.06
  • Docker compose version at least 1.22.0

Setup development environment

Environment variables

Make a .env file

cp .env.example .env

Notable things are:

  • PATH_PHP, PATH_WEB: paths to your code directories. They will be mounted into the containers.
  • DOMAIN and PORT: Domain and port to access the application.
  • COMPOSE_PROJECT_NAME: used to isolate environments when you run multiple projects.

Not very important things:

  • PATH_DATA: Path to the directory you want to persist data to (Database, uploads .etc)
  • PATH_LOGS: Where to persist logs of some services.
  • DB_PORT and DB_TEST_PORT: Ports published by database so you can connect with your DB management tool. Default values depend on which database you choose (5432 & 5433 for Postgres, 3306 & 3307 for MySQL)
  • DOMAIN_BACKEND: Backend domain to access some backend services (traefik, mailhog .etc). Default: backend.localhost

Note: All directory paths can be relative to where you run ./project.

Modules

Make a modules file

cp modules.example modules

Specify which module to include. Example:

postgres
redis
php
frameworks/laravel
web

Available modules are in compose folder. For development, most likely you will only need the above ones.

Start

./project up

Shutdown

./project down

Getting inside containers

To get inside a container you can use

./project sh <service>

e.g

./project sh web

If you are not inside this folder, you can use docker exec to enter containers. Most containers uses alpine image so you can get into them with sh

docker exec -it <container_name> sh

Running commands in container

You can run commands like this

./project exec <service> <command>

Example

./project exec web yarn dev

List all containers

Container names are prefixed with the COMPOSE_PROJECT_NAME environment variable (default: php-project). You can list them all with

./project ps

or use docker ps. e.g.

docker ps -f name=php-project_

Overriding docker-compose file

You can override services or add new services by adding them to a docker-compose.override.yml file.