visit
If you don't just want to check out the repo with the entire setup you can find it on Github
There are two files that tell docker-compose what to spin up. The first is docker-compose.yml and the other is docker-compose.override.yml. The override file is responsible for exposing the host using the hostname dockerhost
. This is useful for both debugging and for referencing other containers more easily.
version: '3.5'
services:
devbox:
container_name: devbox-nginx
build:
context: ./docker/nginx
dockerfile: Dockerfile
ports:
- "9001:80"
volumes:
- .:/app:cached
restart: unless-stopped
depends_on:
- devbox-service
devbox-service:
container_name: devbox-service
build:
context: .
volumes:
- .:/app:cached
- ./docker/service/php.ini:/usr/local/etc/php/conf.d/99-app.ini
- ./docker/service/www.conf:/usr/local/etc/php-fpm.d/www.conf
restart: unless-stopped
environment:
XDEBUG_CONFIG: ${XDEBUG_CONFIG}
APP_ENV: ${APP_ENV}
APP_DEBUG: ${APP_DEBUG}
APP_SECRET: ${APP_SECRET}
env_file:
- .env
- .env.local
depends_on:
- mysql
mysql:
image: mysql:8.0
container_name: devbox-mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: database
ports:
- "3308:3306"
volumes:
- database-volume:/var/lib/mysql
volumes:
database-volume:
driver: "local"
There are two Dockerfiles used. One for php-fpm and the other for Nginx. The one for the app itself is the php-fpm one and it's found at the root of the project and the other one is found in docker/nginx/Dockerfile
.
FROM nginx:stable
COPY default.conf /etc/nginx/conf.d/default.conf
FROM php:8.1-fpm-alpine
LABEL maintainer="alexandrunastase@github"
LABEL description="Devbox Docker image"
# User build args
ARG APP_ENV="prod"
ARG APP_DEBUG="0"
ARG APP_LOG="php://stdout"
# Environment variables
ENV APP_ENV=${APP_ENV}
ENV APP_DEBUG=${APP_DEBUG}
ENV APP_LOG=${APP_LOG}
ENV XDEBUG_CONFIG=""
ENV COMPOSER_NO_INTERACTION=1
# Add PHP user
ARG PHP_USER_ID=1000
ARG PHP_GROUP_ID=1000
RUN set -x \
&& addgroup -g $PHP_GROUP_ID -S php \
&& adduser -u $PHP_USER_ID -D -S -G php php
# Install dependencies
RUN set -ex \
&& docker-php-source extract \
&& apk add --update --no-cache \
${PHPIZE_DEPS} \
curl \
# Runtime deps
icu-dev icu-libs \
libzip-dev zlib-dev \
libxml2-dev \
oniguruma-dev \
&& pecl install xdebug \
&& docker-php-ext-install intl opcache pdo_mysql zip bcmath mbstring sockets pcntl soap sockets ctype > /dev/null \
&& docker-php-ext-enable intl opcache pdo_mysql zip bcmath mbstring sockets pcntl soap sockets ctype \
&& apk del ${PHPIZE_DEPS} \
&& docker-php-source delete
# Copy configuration files
COPY ./docker/service/www.conf /usr/local/etc/php-fpm.d/www.conf
COPY ./docker/service/php.ini $PHP_INI_DIR/conf.d/99-app.ini
COPY ./docker/service/xdebug.ini $PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini
# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY --chown=php . /app
WORKDIR /app
USER php
.PHONY: run
run:
@if [ ! -e ".env.local" ]; then\
cp .env .env.local; \
fi
@docker-compose up -d
@echo "Service is running on //localhost:9001"
.PHONY: install
install:
@docker-compose exec --user="php" -T devbox-service composer install
.PHONY: stop
stop:
@docker-compose stop
.PHONY: enter
enter:
@docker-compose exec --user="php" devbox-service /bin/sh
.PHONY: enter-as-root
enter-as-root:
@docker-compose exec --user="root" devbox-service /bin/sh
.PHONY: test
test:
@docker-compose exec --user="php" -T devbox-service /bin/sh -c 'APP_ENV="test" ./bin/phpunit --testdox'
.PHONY: destroy
destroy:
@docker-compose down --rmi local
PHP Remote Debugging
as CLI interpreter. Make sure the local interpreter is removedDocker Compose
as the configuration type and devbox-service
as the serviceConnect to existing container
In the docker-compose the port 9001 is mapped to the localhost so you can check if everything is working after running:
make run
make install
There is one endpoint defined call //localhost:9001/healthz
which should return a 200 status code.
make test
make enter