Skip to content

Commit 86f1354

Browse files
Merge pull request #27 from HarkuLi/main
Let Xdebug work without specific settings for different OSes + some slight improvement
2 parents 65a34cd + 9597571 commit 86f1354

File tree

5 files changed

+25
-31
lines changed

5 files changed

+25
-31
lines changed

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,11 @@ RUN apk --no-cache add git openssh bash; \
212212
# Enable Xdebug
213213
docker-php-ext-enable xdebug
214214

215-
# For Xdebuger to work, it needs the docker host ID
215+
# For Xdebuger to work, it needs the docker host IP
216216
# - in Mac AND Windows, `host.docker.internal` resolve to Docker host IP
217217
# - in Linux, `172.17.0.1` is the host IP
218+
# By default, `host.docker.internal` is set as extra host in docker-compose.yml, so it also works in Linux without any
219+
# additional setting. This env is reserved for people who want to customize their own compose configuration.
218220
ENV XDEBUG_CLIENT_HOST="host.docker.internal"
219221

220222
# ---------------------------------------------------- Scripts ---------------------------------------------------------

Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ COMMAND ?= /bin/sh
66

77
# --------------------------
88

9-
.PHONY: build deploy start stop logs restart shell up rm help
9+
.PHONY: deploy up build-up build down start stop logs images ps command \
10+
command-root shell-root shell restart rm help
1011

1112
deploy: ## Start using Prod Image in Prod Mode
1213
${COMPOSE_PREFIX_CMD} docker-compose -f docker-compose.prod.yml up --build -d
@@ -46,10 +47,10 @@ command-root: ## Execute command as root ( make command-root COMMAND=<command>
4647
@${COMPOSE_PREFIX_CMD} docker-compose run --rm -u root app ${COMMAND}
4748

4849
shell-root: ## Enter container shell as root
49-
@${COMPOSE_PREFIX_CMD} docker-compose exec -u root app /bin/bash
50+
@${COMPOSE_PREFIX_CMD} docker-compose exec -u root app /bin/sh
5051

5152
shell: ## Enter container shell
52-
@${COMPOSE_PREFIX_CMD} docker-compose exec app /bin/bash
53+
@${COMPOSE_PREFIX_CMD} docker-compose exec app /bin/sh
5354

5455
restart: ## Restart container
5556
@${COMPOSE_PREFIX_CMD} docker-compose restart

README.md

+15-20
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
## How to use with my project ?
5454

55-
- Copy this repository `Dockerfile`, `docker` Directory, `Makefile`, and `.dockerignore` to your application root directory and configure it to your needs.
55+
- Copy this repository `Dockerfile`, `docker` Directory, `Makefile`, `docker-compose.yml`, `docker-compose.prod.yml` and `.dockerignore` to your application root directory and configure it to your needs.
5656

5757
## How to configure image to run my project ?
5858

@@ -79,7 +79,7 @@ Your application will be split into two components.
7979

8080
# Requirements
8181

82-
- [Docker 20.05 or higher](https://docs.docker.com/install/)
82+
- [Docker 20.10.0 or higher](https://docs.docker.com/install/)
8383
- [Docker-Compose 1.27 or higher](https://docs.docker.com/compose/install/) (optional)
8484
- PHP >= 7 Application
8585

@@ -88,7 +88,7 @@ Your application will be split into two components.
8888
#### 1. Add Template to your repo.
8989

9090
1. Download This Repository
91-
2. Copy `Dockerfile`, `docker` Directory, `Makefile`, and `.dockerignore` Into your Application Repository.
91+
2. Copy `Dockerfile`, `docker` Directory, `Makefile`, `docker-compose.yml`, `docker-compose.prod.yml` and `.dockerignore` Into your Application Repository.
9292

9393
OR
9494

@@ -114,18 +114,18 @@ OR
114114
However, in an environment where CI/CD pipelines will build the image, they will need to supply some build-time arguments for the image. (tho defaults exist.)
115115

116116
#### Build Time Arguments
117-
| **ARG** | **Description**
118-
| **Default** |
119-
--------------------|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
120-
| `PHP_VERSION` | PHP Version used in the Image | `7.4` | | `PHP_ALPINE_VERSION` | Alpine
121-
Version for the PHP Image | `3.15` | | `NGINX_VERSION` | Nginx Version | `1.21` | | `COMPOSER_VERSION` |
122-
Composer Version used in Image | `2.0` | | `COMPOSER_AUTH` | A Json Object with Bitbucket or Github token to
123-
clone private Repos with composer.</br>[Reference](https://getcomposer.org/doc/03-cli.md#composer-auth) | `{}`
124-
| | `RUNTIME_DEPS` | List of all OS Packages needed for PHP Runtime | `zip` | | `XDEBUG_VERSION` | Xdebug
125-
Version to use in Development Image | `3.0.3` |
126-
127-
#### Image Targets
128-
117+
118+
| **ARG** | **Description** | **Default** |
119+
|----------------------|-----------------|-------------|
120+
| `PHP_VERSION` | PHP Version used in the Image | `7.4` |
121+
| `PHP_ALPINE_VERSION` | Alpine Version for the PHP Image | `3.15` |
122+
| `NGINX_VERSION` | Nginx Version | `1.21` |
123+
| `COMPOSER_VERSION` | Composer Version used in Image | `2.0` |
124+
| `COMPOSER_AUTH` | A Json Object with Bitbucket or Github token to clone private Repos with composer.</br>[Reference](https://getcomposer.org/doc/03-cli.md#composer-auth) | `{}` |
125+
| `XDEBUG_VERSION` | Xdebug Version to use in Development Image | `3.1.3` |
126+
127+
#### Image Targets
128+
129129
| **Target** | Env | Desc | Size | Based On |
130130
|------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|-------------------------------|
131131
| app | Production | The PHP Application with immutable code/dependencies. By default starts `PHP-FPM` process listening on `9000`. Command can be extended to run any PHP Consumer/Job, entrypoint will still start the pre-run setup and then run the supplied command. | ~135mb | PHP Official Image (Alpine) |
@@ -198,11 +198,6 @@ In `docker/` directory there is `post-build-*` and `pre-run-*` scripts that are
198198
fail when it cannot connect to
199199
DB. [Make sure you configure doctrine to avoid this extra DB Check connection.](https://symfony.com/doc/current/reference/configuration/doctrine.html#:~:text=The-,server_version,-option%20was%20added)
200200
201-
3. Xdebug not working
202-
203-
- Xdebug is configured to work with Linux, to make it work for Mac/Windows, please change `XDEBUG_CLIENT_HOST` env
204-
variable to `host.docker.internal` in `docker-compose.yml` file.
205-
206201
# License
207202
208203
[MIT License](https://raw.githubusercontent.com/sherifabdlnaby/kubephp/blob/master/LICENSE)

docker-compose.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ services:
1111
COMPOSER_AUTH: "{}"
1212
APP_BASE_DIR: ${APP_BASE_DIR-.}
1313
restart: unless-stopped
14-
environment:
15-
# For Xdebuger to work, it needs the docker host ID
16-
# - in Mac AND Windows, `host.docker.internal` resolve to Docker host IP
17-
# - in Linux, `172.17.0.1` is the host IP
18-
XDEBUG_CLIENT_HOST: ${XDEBUG_CLIENT_HOST-host.docker.internal}
14+
extra_hosts:
15+
- "host.docker.internal:host-gateway"
1916
volumes:
2017
- ${APP_BASE_DIR-.}:/app
2118

docker/fpm/fpm.conf

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ pm = dynamic
1818
pm.start_servers = 2
1919
pm.min_spare_servers = 2
2020
pm.max_spare_servers = 2
21-
pm.process_idle_timeout = 10s
2221
pm.max_children = 50
2322

2423
; do not clear environment variables sent to the PHP Script, pass OS env vars to PHP. (Important for K8S)
2524
clear_env = no
2625

27-
; Disable access logs in fpm's stdout/err as it will be in nginx acces logs.
26+
; Disable access logs in fpm's stdout/err as it will be in nginx access logs.
2827
;access.log = /dev/stderr
2928

3029
; Run as www-data

0 commit comments

Comments
 (0)