Skip to content

Instantly share code, notes, and snippets.

@PurpleBooth
Last active February 25, 2021 16:36
Show Gist options
  • Save PurpleBooth/82a183e8e0576db441b2b716e884bbf8 to your computer and use it in GitHub Desktop.
Save PurpleBooth/82a183e8e0576db441b2b716e884bbf8 to your computer and use it in GitHub Desktop.
A sensible PHP in Docker env
FROM php:5-cli
RUN apt-get update \
&& apt-get install -y \
git software-properties-common python-software-properties libicu-dev zlib1g-dev curl subversion bash \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl \
&& docker-php-ext-configure opcache \
&& docker-php-ext-install opcache \
&& echo default_mimetype="" > /usr/local/etc/php/conf.d/default_mimetype.ini
RUN curl -o composer-setup.php https://getcomposer.org/installer \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN curl -L https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.1.0/php-cs-fixer.phar \
-o /usr/local/bin/php-cs-fixer \
&& chmod a+x /usr/local/bin/php-cs-fixer
COPY "memory-limit-php.ini" "/usr/local/etc/php/conf.d/memory-limit-php.ini"
WORKDIR "/code"
ENTRYPOINT ["/bin/bash"]
version: '2'
services:
shell:
build: container/shell
volumes:
- .:/code
- /etc/passwd:/etc/passwd
- /etc/group:/etc/group
- $HOME:$HOME
- "$SSH_AUTH_SOCK:/ssh-auth.sock"
environment:
- SSH_AUTH_SOCK=/ssh-auth.sock
network_mode: host
web:
build: container/web
ports:
- "3000"
mysql:
image: mysql

A sensible Docker/PHP Workflow

You can start the app like you would normally. Make requests to the server, and all the usual stuff.

docker-compose up

But if you want to do some commandline stuff

docker-compose run --user "$(id -u):$(id -g)" shell

Because home is mounted on home, all the cache fills generated by PHP are in place and you don't have to, for example, redownload the composer dependencies every time.

If you're wondering about the User stuff it's to prevent permissions errors from running things as root. This is less of an issue on OSX.

Your container/web container can be the container you use for production, without any of the development guff that sort of accrues sometimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment