duanjiao5082
2018-06-27 13:05 阅读 549
已采纳

多个项目之间的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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duananyu9231 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

    点赞 评论 复制链接分享

相关推荐