I was given a repo containing a PHP Application using Docker/Symfony. I'm able to successfully run docker-compose up --build
and it looks like everything is running successfully. When I run docker ps --all
I see everything I'm expecting
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
65d7f22b6b13 nginx "nginx -g 'daemon ..." 16 minutes ago Up 7 minutes 0.0.0.0:8086->80/tcp symfony_nginx_1
4fa3c58d1eea symfony_fpm "docker-php-entryp..." 16 minutes ago Up 7 minutes 9000/tcp symfony_fpm_1
7316d40b1b8c mysql:5.5 "docker-entrypoint..." 16 minutes ago Up 7 minutes 3306/tcp symfony_mysql_1
cac0757e2f6d redis:latest "docker-entrypoint..." 16 minutes ago Up 7 minutes 6379/tcp symfony_redis_1
When I try to access localhost:8086
on my browser, I get connection refused. I though maybe my local config might be janky and tried this on another machine with the same results. I tried to get the logs of the nginx image by running docker logs 65d7f22b6b13
but it returns nothing.
Is there something I'm not understanding about docker/nginx and port forwarding that I'm doing incorrectly? Below is my docker config
version: '2'
services:
nginx:
image: nginx
ports:
- "8086:80"
volumes:
- ./:/var/www/symfony
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
links:
- fpm
fpm:
build: docker/php-fpm/
links:
- redis
- mysql
volumes:
- ./:/var/www/symfony
- ./docker/php-fpm/php-ini-overrides.ini:/usr/local/etc/php/conf.d/99-overrides.ini
mysql:
image: mysql:5.5
environment:
MYSQL_DATABASE: devdb
MYSQL_USER: devdb
MYSQL_PASSWORD: devdb
MYSQL_ROOT_PASSWORD: root
volumes:
- ./backup.sql.gz:/docker-entrypoint-initdb.d/backup.sql.gz
redis:
image: redis:latest
I'm on OSX 10.11.6 - Any help appreciated. Symfony and Docker are new to me.
edit Below is my nginx config file - I updated listen
to use 127.0.0.1:8086
but still see it using 0.0.0.0
when I run docker ps
server {
listen 127.0.0.1:80 default;
client_max_body_size 108M;
access_log /var/log/nginx/symfony.access.log;
root /var/www/symfony/web;
rewrite ^/index\.php/?(.*)$ /$1 permanent;
try_files $uri @rewriteapp;
location @rewriteapp {
rewrite ^(.*)$ /index.php/$1 last;
}
# Deny all . files
location ~ /\. {
deny all;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
send_timeout 1800;
fastcgi_read_timeout 1800;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "error_log=/var/log/nginx/routemap3_php_errors.log";
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
}
# Statics
location /(bundles|media) {
access_log off;
expires 30d;
try_files $uri @rewriteapp;
}
}
Your answer is in your question:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
65d7f22b6b13 nginx "nginx -g 'daemon ..." 16 minutes ago Up 7 minutes 0.0.0.0:8086->80/tcp symfony_nginx_1
Now if you read the column PORTS
carefully you will see 0.0.0.0:8086->80/tcp
, which means that your local loop 0.0.0.0
on port 8086
is mapped to the port 80
of your ngnix
container, and this with the tcp
protocol.
So your correct url to access is http://0.0.0.0:8086/
You will also have to change your NGINX config to adapt to that, it should read:
listen 0.0.0.0:80;
or even better:
listen *:80;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.