access docker container's port

浪尽此生 提交于 2019-12-24 10:59:40

问题


I have two websites running in my local computer:

App A: a wordpress app running in docker and is accessible from this: http://localhost:5000

App B: another app running in the local web server http://localhost:80

The problem is, when I try to access the wordpress control panel (http://localhost:5000/wp-admin), the browser shows NOT Found error, and the URL on the browser address bar shows "http://localhost/wp-admin/" (port 5000 automatically disappeared).

My guess is that the browser is trying to access wp-admin from App B (port 80) instead of App A (port 5000).

Why is that and how to force browser to use my specificed port?

I tested in both Chrome and Firefox, they behave the same.

This is my docker-compose.yml:

version: '3'

services:
  service_website:
    build: ./services/website
    volumes:
      - ./services/website/source:/var/www/app
      - ./services/website/config/nginx.site.conf:/etc/nginx/conf.d/default.conf
    ports:
      - 5000:80

  php:
    build: ./services/php-fpm
    volumes:
      - ./services/website/source:/var/www/app
      - ./services/php-fpm/config/php.ini:/usr/local/etc/php/php.ini

my nginx config:

server {
    index index.html index.php;
    listen 80 default_server;
    server_name localhost php-docker.local;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;    
    root /var/www/app/public;

    location ~ \.php$ {
        try_files $uri =404;
        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 PATH_INFO $fastcgi_path_info;
    }    
}

来源:https://stackoverflow.com/questions/52785798/access-docker-containers-port

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!