Docker compose redirects port 9085 to port 80, unless I specify an additional path after the address, for example index.php.
docker-compose.yaml
version: "3.8"
services:
web-nginx:
container_name: web-nginx
build: ./docker/nginx
command: nginx -g "daemon off;"
links:
- web-php
ports:
- "9085:80"
- "4444:443"
volumes:
- ./logs/nginx:/var/log/nginx
- ./src:/var/www/html
web-php:
container_name: web-php
build: ./docker/php
ports:
- "9001:9000"
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
web-mysql:
image: mysql:8.0.32
container_name: web-mysql
env_file:
- ./env/mysql.env
ports:
- "3307:3306"
volumes:
- ./database/mysql:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password'
default.conf (nginx):
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php;
# index.html index.htm index.nginx-debian.html;
server_name mysite;
location / {
# pass PHP scripts to FastCGI server
#
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass web-php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
#location ~ /\.ht {
# deny all;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
client_max_body_size 1024M;
}
docker/nginx/Dockerfile:
FROM nginx:1.25.4
ADD default.conf /etc/nginx/conf.d/default.conf
docker/php/Dockerfile:
FROM php:8.2-fpm
RUN apt-get update
RUN docker-php-ext-install pdo pdo_mysql mysqli
After creating the images, everything starts up normally.
docker ps:
ttsv@docker:~/wp3$ docker compose ps
WARN[0000] /home/ttsv/wp3/docker-compose.yaml: `version` is obsolete
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
web-mysql mysql:8.0.32 "docker-entrypoint.s…" web-mysql 5 seconds ago Up 4 seconds 33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp
web-nginx wp3-web-nginx "/docker-entrypoint.…" web-nginx 5 seconds ago Up 4 seconds 0.0.0.0:9085->80/tcp, :::9085->80/tcp, 0.0.0.0:4444->443/tcp, :::4444->443/tcp
web-php wp3-web-php "docker-php-entrypoi…" web-php 5 seconds ago Up 4 seconds 0.0.0.0:9001->9000/tcp, :::9001->9000/tcp
ttsv@docker:~/wp3$
However, when I try to access the container at http://172.16.1.180:9085/
, it redirects me to http://172.16.1.180/
, where I have another Docker web running on port 80. If I stop this container, it still tries to redirect to it. However, when I add a specific path, for example http://172.16.1.180:9085/index.php
, then it doesn’t redirect and stays at the current address and port. Does anyone have an idea why this behavior is happening?
OS:
ttsv@docker:~/wp3$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
Docker version:
ttsv@docker:~/wp3$ docker version
Client: Docker Engine - Community
Version: 26.0.0
API version: 1.45
Go version: go1.21.8
Git commit: 2ae903e
Built: Wed Mar 20 15:18:01 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 26.0.0
API version: 1.45 (minimum version 1.24)
Go version: go1.21.8
Git commit: 8b79278
Built: Wed Mar 20 15:18:01 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.28
GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
runc:
Version: 1.1.12
GitCommit: v1.1.12-0-g51d5e94
docker-init:
Version: 0.19.0
GitCommit: de40ad0