duanjiao5082
2018-06-27 13:05
浏览 785
已采纳

多个项目之间的Docker连接被拒绝

I set up 2 projects (Admin and API) and try to move into docker on local.

I can access the running web instances on both without any problems, but when the Admin tries to make a Curl requests to the API, I get a cURL error:

cURL error 7: Failed to connect to localhost port 8080

This is my docker-compose.yml file contents:

version: "3.1"
services:

    memcached:
      image: memcached:alpine
      container_name: project-admin-memcached

    redis:
      image: redis:alpine
      container_name: project-admin-redis

    mariadb:
      image: mariadb:10.1
      container_name: project-admin-mariadb
      working_dir: /application
      volumes:
        - ./Projects:/application
      environment:
        - MYSQL_ROOT_PASSWORD=docker
        - MYSQL_DATABASE=db_test
        - MYSQL_USER=test
        - MYSQL_PASSWORD=test
      ports:
        - "8083:3306"

# docker-compose exec webserver sh
# docker exec -it project-admin-webserver nginx -s reload
    webserver:
      image: nginx:alpine
      container_name: project-admin-webserver
      working_dir: /application
      volumes:
          - ./Projects/Api:/application/api
          - ./Projects/Admin:/application/admin
          - ./Docker/nginx:/etc/nginx/conf.d
      ports:
          - "8080:8080"
          - "8090:8090"

# docker-compose exec php-fpm bash
    php-fpm:
      build: Docker/php-fpm
      container_name: project-admin-php-fpm
      working_dir: /application
      volumes:
          - ./Projects:/application
          - ./Docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini

I can access both projects from my browser with:

http://localhost:8080/ <= API

http://localhost:8090/ <= Admin

How can I fix this?

图片转代码服务由CSDN问答提供 功能建议

我设置了2个项目(Admin和API),并尝试进入本地的docker。 \ n

我可以毫无问题地访问正在运行的Web实例,但是当管理员尝试向API发出Curl请求时,我收到一个cURL错误:

cURL错误7:无法连接到localhost端口8080

这是我的docker-compose.yml文件内容:

  version:“3.1”
services:
 
 memcached:
 image:memcached:alpine 
 container_name:project-admin-memcached 
 
 redis:
 image:redis:  alpine 
 container_name:project-admin-redis 
 
 mariadb:
 image:mariadb:10.1 
 container_name:project-admin-mariadb 
 working_dir:/ application 
 volumes:
  -  ./Projects:/  application 
 environment:
  -  MYSQL_ROOT_PASSWORD = docker 
  -  MYSQL_DATABASE = db_test 
  -  MYSQL_USER = test 
  -  MYSQL_PASSWORD = test 
 ports:
  - “8083:3306”
 
#docker-compose exec webserver sh 
#docker exec -it project-admin-webserver nginx -s reload 
 webserver:
 image:nginx:alpine 
 container_name:project-  admin-webserver 
 working_dir:/ application 
 volumes:
  -  ./Projects/Api:/application/api
  -  ./Projects/Admin:/application/admin
  -  ./Docker/nginx:/etc  /nginx/conf.d
 ports:
  - “8080:8080”
  - “8090:8090”
 
#docker-compose exec php-fpm bash 
 php-fpm:
 build:Docker  / php-fpm 
 container_name:project-admin-php-fpm 
 working_dir:/ application 
 volumes:
  -  ./Projects:/application
  -  ./Docker/php-fpm/php-ini-overrides  .ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini 
   
 
 

我可以通过浏览器访问这两个项目:

http:// localhost:8080 / &lt; = API

http:// localhost:8090 / &lt; = Admin

我该如何解决这个问题?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • duananyu9231 2018-06-27 13:12
    最佳回答

    inside your docker network (create by default with a compose), you have to use the container name. So inside a container you have to use http://webserver:8080

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题