Skip to main content

Docker for small dev setups

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· One min read
Daniel Ruf
Full Stack Developer

Old PHP projects often still use Composer 1 and require an old PHP version to run. To make life easier for the other developers, I have created some efficient and small development setups based on Docker.

The commands used are normally a bit longer and hard to remember. So we use a bin folder and place our bash scripts there. In these bash scripts, we run specific Docker images. This prevents that we clutter our local setups with many different old PHP versions, which also often leads to conflicts.

The following one-liner scripts are used in our old Symfony projects, which still use PHP 7.1 and Composer 1.

** bin/composer** (uses Composer 1)

#!/usr/bin/env bash

docker run --rm --interactive --tty --volume "$PWD":/app composer:1 "$@"

bin/dev-php (uses the built-in web server of PHP 7.1)

#!/usr/bin/env bash

docker run -it --rm -v "$PWD":/usr/src/app -p 0.0.0.0:8000:8000 -w /usr/src/app php:7.1-cli php -S 0.0.0.0:8000 -t public

** bin/dev** (uses the Symfony dev server on PHP 7.1)

#!/usr/bin/env bash

docker run -it --rm -v "$PWD":/usr/src/app -p 0.0.0.0:8000:8000 -w /usr/src/app php:7.1-cli php bin/console server:run --env dev 0.0.0.0