Using Windows 10 with Docker, I'm trying to reach my Linux container running nginx. I'm trying to access my localhost (or via an IP address) through a web browser and I get "cannot reach this page". Inside my nginx container if I try and access localhost or direct ip with CURL I get "Connection Refused". I am a complete beginner to docker with Windows and its a nightmare to figure out! Have tried localhost:8080 and 172.18.0.4:8080 (which is the IP shown in docker inspect nginx_1)
Here is my docker-compose.yml
version: '2'
volumes:
database_data:
driver: local
services:
nginx:
image: nginx:latest
ports:
- 8080:80
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d
volumes_from:
- php
php:
build: ./docker/php
expose:
- 9000
volumes:
- .:/var/www/html
mysql:
image: mysql:latest
expose:
- 3306
volumes:
- database_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
And here is my nginx default.conf file:
server {
listen 80 default_server;
root /var/www/html/public;
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV development;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
What is missing from my config that is preventing me access to my index.php file from my host machine?
Many thanks!
Just tested your setup and it worked fine for me.
Since you are already getting a "cannot reach this page" from your browser, the issue is in already in the nginx, and not the php container. when the php container is not working, the page will load and give you an nginx Error like "Cannot find file" (e.g. the index.php) or similar.
Can you check if the nginx config is correctly loaded into the container? To do so, type "docker exec -it sh" and navigate to the /etc/nginx/conf.d/default.conf file
additional info
you cant access the nginx container via 172.18.0.4:8080. This is the ip of the container, but you map the port 8080 only to your host machine. The default port of nginx container is 80. Since the "normal" container ports are only availibe inside the docker network, you cant access the container this way.