Skip to content

Commit 26f424d

Browse files
sveneldVolodymyr Panivko
authored andcommitted
chore: make docker-compose ports configurable via env variables
Allow overriding host ports with DB_PORT, WEB_PORT, NGINX_PORT, PMA_PORT environment variables to avoid conflicts with other services. Update INSTALL.md and CONTRIBUTING.md to document the new variables.
1 parent f5802e3 commit 26f424d

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ How to start web over docker
88
2. optional - if you want https. Generate keys to docker-data/nginx/ssl/bikesharing.loc.crt and bikesharing.loc.key. Uncomment lines in docker-data/nginx/nginx.conf and docker-compose.yml
99
3. run `docker compose up -d`
1010
4. go to `http://localhost:8100`, phpmyadmin is on url `http://localhost:81`, mysql server `db`, mysql user `root`, mysql password `password`, mysql database `bikesharing`
11+
12+
To avoid port conflicts with other services, you can override host ports via environment variables:
13+
```bash
14+
DB_PORT=3308 WEB_PORT=8200 docker compose up -d
15+
```
16+
17+
Available port variables: `NGINX_PORT` (default 80), `DB_PORT` (default 3306), `WEB_PORT` (default 8100), `PMA_PORT` (default 81).

INSTALL.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ cp .env.dist .env.dev
2525
docker compose up -d
2626
```
2727

28+
To avoid port conflicts, you can override host ports via environment variables:
29+
```bash
30+
DB_PORT=3308 WEB_PORT=8200 docker compose up -d
31+
```
32+
2833
4. Install PHP dependencies:
2934
```bash
3035
docker compose exec web composer install
@@ -38,12 +43,12 @@ The application will be available at:
3843

3944
Services overview
4045
----------
41-
| Service | Port | Description |
42-
|---------|------|-------------|
43-
| Nginx | 80 | Reverse proxy |
44-
| PHP 8.4 (Apache) | 8100 | Application server |
45-
| MariaDB 10.3 | 3306 | Database |
46-
| PHPMyAdmin | 81 | Database admin UI |
46+
| Service | Default port | Env variable | Description |
47+
|---------|-------------|--------------|-------------|
48+
| Nginx | 80 | `NGINX_PORT` | Reverse proxy |
49+
| PHP 8.4 (Apache) | 8100 | `WEB_PORT` | Application server |
50+
| MariaDB 10.3 | 3306 | `DB_PORT` | Database |
51+
| PHPMyAdmin | 81 | `PMA_PORT` | Database admin UI |
4752

4853
Configuration (.env)
4954
----------

docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ services:
99
#- ./docker-data/nginx/ssl/bikesharing.loc.crt:/etc/nginx/certs/bikesharing.loc.crt
1010
#- ./docker-data/nginx/ssl/bikesharing.loc.key:/etc/nginx/certs/bikesharing.loc.key
1111
ports:
12-
- 80:80
12+
- ${NGINX_PORT:-80}:80
1313
#- 443:443
1414
links:
1515
- web
1616
db:
1717
image: mariadb:10.3
1818
ports:
19-
- 3306:3306
19+
- ${DB_PORT:-3306}:3306
2020
environment:
2121
MYSQL_ROOT_PASSWORD: password
2222
MYSQL_DATABASE: bikesharing
@@ -29,7 +29,7 @@ services:
2929
web:
3030
build: .
3131
ports:
32-
- "8100:80"
32+
- "${WEB_PORT:-8100}:80"
3333
volumes:
3434
- ./:/var/www/html/
3535
- ./docker-data/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
@@ -43,7 +43,7 @@ services:
4343
links:
4444
- db
4545
ports:
46-
- 81:80
46+
- ${PMA_PORT:-81}:80
4747
environment:
4848
- PMA_HOST=db
4949
- PMA_USER=root

0 commit comments

Comments
 (0)