Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Docker Kubernetes:同一pod中的两个容器无法通过本地主机连接_Docker_Kubernetes_Docker Compose - Fatal编程技术网

Docker Kubernetes:同一pod中的两个容器无法通过本地主机连接

Docker Kubernetes:同一pod中的两个容器无法通过本地主机连接,docker,kubernetes,docker-compose,Docker,Kubernetes,Docker Compose,我正在尝试使用Kubernetes吊舱中的localhost连接两个容器。但我不能这么做 库伯内特斯 我可以使用docker compose轻松完成同样的操作: version: "3.3" services: db: image: mysql:8.0 restart: always networks: - database environment: - MYSQL_ROOT_PASSWORD=qwertyuiop

我正在尝试使用Kubernetes吊舱中的localhost连接两个容器。但我不能这么做

库伯内特斯 我可以使用docker compose轻松完成同样的操作:

version: "3.3"
services: 
  db:
    image: mysql:8.0
    restart: always
    networks:
      - database
    environment:
      - MYSQL_ROOT_PASSWORD=qwertyuiop
      - MYSQL_DATABASE=foody
      - MYSQL_USER=iiitbspring
      - MYSQL_PASSWORD=iiitbspring
    volumes:
      - db-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 20s
      retries: 10

  server:
    build: ./backend/
    image: #################
    depends_on: 
      - db
    networks: 
      - database
      - server
    environment: 
      - username=iiitbspring
      - password=iiitbspring
      - DB_URL=jdbc:mysql://db:3306?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC
    expose:
      - "8686"
    ports:
      - "8686:8686"
    # healthcheck:
    #   test: ["CMD-SHELL", "curl -f http://localhost:4444/actuator/health || exit 1"]
    #   timeout: 10s
    #   retries: 6

  app:
    build: ./foodyFrontEnd/
    image: #################
    networks: 
      - server
    ports:
      - "3000:80"
    depends_on: 
      - server

volumes:
  db-data:

networks:
  database:
    driver: bridge
  server:
关于我想要运行的两个容器:一个在端口8686运行springboot应用程序的后端容器,另一个是在端口80上使用nginx运行angular的前端容器

我得到的错误是: 访问URL时:http://remote-url:3000/ 我有我的角度页面,但在控制台上我可以看到错误:GEThttp://localhost:8686/api/foods net::ERR_CONNECTION_拒绝,我的webapp试图建立到后端的连接

我尝试在容器内卷曲,但由于阿尔卑斯山的原因,我无法运行它。

正如@David Maze所说:

问题是angular在客户端运行,所以当我 正在向localhost发送请求,然后该主机正在尝试连接到上的端口 桌面系统


谢谢@David Maze,我刚刚错过了这一点。

听起来您的应用程序中有什么东西正在将
localhost
URL发送到浏览器,然后浏览器正试图连接到桌面系统上的该端口。是什么生成了
../api/foods
URL?为什么不在单独的部署中运行“app”和“api server”呢?我也想这样做,但我不知道如何将URL发送到服务器。我不熟悉angular。在angular应用程序中,我创建了一个带值的常量,在整个应用程序中,我在http get中使用这个变量:http.get()。你好。Angular不在服务器上运行。在浏览器中的客户端上运行Angular。当浏览器运行angular应用程序并调用locahost:xxx时,它实际上会击中客户端计算机,这就是我所想的;你是如何解决这个问题的?您是否必须将它们部署到单独的pod中,并以某种方式映射DNS/IP名称?
version: "3.3"
services: 
  db:
    image: mysql:8.0
    restart: always
    networks:
      - database
    environment:
      - MYSQL_ROOT_PASSWORD=qwertyuiop
      - MYSQL_DATABASE=foody
      - MYSQL_USER=iiitbspring
      - MYSQL_PASSWORD=iiitbspring
    volumes:
      - db-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 20s
      retries: 10

  server:
    build: ./backend/
    image: #################
    depends_on: 
      - db
    networks: 
      - database
      - server
    environment: 
      - username=iiitbspring
      - password=iiitbspring
      - DB_URL=jdbc:mysql://db:3306?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC
    expose:
      - "8686"
    ports:
      - "8686:8686"
    # healthcheck:
    #   test: ["CMD-SHELL", "curl -f http://localhost:4444/actuator/health || exit 1"]
    #   timeout: 10s
    #   retries: 6

  app:
    build: ./foodyFrontEnd/
    image: #################
    networks: 
      - server
    ports:
      - "3000:80"
    depends_on: 
      - server

volumes:
  db-data:

networks:
  database:
    driver: bridge
  server: