发送API请求在两个Docker容器之间。

huangapple go评论55阅读模式
英文:

Sending API-requests between two docker containers

问题

以下是翻译好的部分:

我在我的Mac OSX上运行了一个Magento2的DDEV环境(Ventura)。

用于测试目的,我在我的ddev项目的docker-compose.yaml中包括了Nifi,位置是.ddev/docker-compose.nifi.yaml

下面是这个docker-compose文件,目前非常简单。Nifi正常运行,因为我可以登录等等,尽管它目前还不是持久性的,但这是另一个问题。

version: '3'
services:
  nifi:
    image: apache/nifi:latest
    container_name: ddev-${DDEV_SITENAME}-nifi
    ports:
      # HTTP
      - "8080:8080"
      # HTTPS
      - "8443:8443"
    volumes:
        # - ./nifi/database_repository:/opt/nifi/nifi-current/database_repository
        # - ./nifi/flowfile_repository:/opt/nifi/nifi-current/flowfile_repository
        # - ./nifi/content_repository:/opt/nifi/nifi-current/content_repository
        # - ./nifi/provenance_repository:/opt/nifi/nifi-current/provenance_repository
        # - ./nifi/state:/opt/nifi/nifi-current/state
        # - ./nifi/logs:/opt/nifi/nifi-current/logs
        # - ./nifi/conf/login-identity-providers.xml:/opt/nifi/nifi-current/conf/login-identity-providers.xml
        - ".:/mnt/ddev_config"

我只想从Nifi向我的Magento2模块发送一个POST请求。

我尝试了几个IP地址,这些IP地址来自docker inspect ddev-ddev-magento2-web,但我总是收到"Connection refused"的错误消息。

我通过docker network ls得到的输出如下:

NETWORK ID     NAME                         DRIVER    SCOPE
95bea4031396   bridge                       bridge    local
692b58ca294e   ddev-ddev-magento2_default   bridge    local
46be47991abe   ddev_default                 bridge    local
7e19ae1626f1   host                         host      local
f8f4f1aeef04   nifi_docker_default          bridge    local
dbdba30546d7   nifi_docker_mynetwork        bridge    local
ca12e667b773   none                         null      local

我的Magento2模块正常工作,因为从Postman向它发送请求都可以正常运行。

英文:

I have running a DDEV-Environment for Magento2, locally on my Mac OSX (Ventura)

https://ddev.readthedocs.io/en/stable/users/quickstart/#magento-2

For testing purpose I included Nifi per docker-compose.yaml inside my ddev project .ddev/docker-compose.nifi.yaml

Below you can see the docker-compose, which is really minimal at this point. Nifi works like expected, because I can login etc, although it is not persistent yet, but thats a different problem

version: '3'
services:
  nifi:
    image: apache/nifi:latest
    container_name: ddev-${DDEV_SITENAME}-nifi
    ports:
      # HTTP
      - "8080:8080"
      # HTTPS
      - "8443:8443"
    volumes:
        # - ./nifi/database_repository:/opt/nifi/nifi-current/database_repository
        # - ./nifi/flowfile_repository:/opt/nifi/nifi-current/flowfile_repository
        # - ./nifi/content_repository:/opt/nifi/nifi-current/content_repository
        # - ./nifi/provenance_repository:/opt/nifi/nifi-current/provenance_repository
        # - ./nifi/state:/opt/nifi/nifi-current/state
        # - ./nifi/logs:/opt/nifi/nifi-current/logs
        # - ./nifi/conf/login-identity-providers.xml:/opt/nifi/nifi-current/conf/login-identity-providers.xml
        - ".:/mnt/ddev_config"

All I want to do is sending a POST-requst from Nifi to my Magento2 module.

I tried several IPs now, which I got from docker inspect ddev-ddev-magento2-web but I always receive "Connection refused"

My output from docker network ls:

NETWORK ID     NAME                         DRIVER    SCOPE
95bea4031396   bridge                       bridge    local
692b58ca294e   ddev-ddev-magento2_default   bridge    local
46be47991abe   ddev_default                 bridge    local
7e19ae1626f1   host                         host      local
f8f4f1aeef04   nifi_docker_default          bridge    local
dbdba30546d7   nifi_docker_mynetwork        bridge    local
ca12e667b773   none                         null      local

My Magento2-Module is working properly, because sending requests from Postmanto it works fine

答案1

得分: 1

不要翻译的代码部分:

services:
  nifi:
    image: apache/nifi:latest
    container_name: ddev-${DDEV_SITENAME}-nifi
    container_name: "ddev-${DDEV_SITENAME}-someservice"
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: ${DDEV_APPROOT}
    expose:
      - "8080"
    environment:
      - VIRTUAL_HOST=$DDEV_HOSTNAME
      - HTTP_EXPOSE=8080:8080
      - HTTPS_EXPOSE=9999:8080
    volumes:
        - ".:/mnt/ddev_config"

翻译好的部分:

你不需要你拥有的大部分内容。请删除ports语句,这完全不需要;如果你需要任何内容,你将需要一个expose。但我怀疑在这种情况下你是否需要它?

你可以查看文档:

然后创建一个名为.ddev/docker-compose.nifi.yaml的文件,内容如下:

“web”容器的名称是在你的nifi容器内部,假设你的nifi监听端口8080,你可以使用curl http://web:8080来访问它。

我不知道你想要实现什么,但这可能会帮助你入门。欢迎加入DDEV Discord频道以获取更多互动帮助。

英文:

You don't want most of what you have. Please remove the ports statement, which you shouldn't need at all; if you need anything, you'll need an expose. But I doubt you need that in this case?

You'll want to look at the docs:

Then create a .ddev/docker-compose.nifi.yaml with something like

services:
  nifi:
    image: apache/nifi:latest
    container_name: ddev-${DDEV_SITENAME}-nifi
    container_name: "ddev-${DDEV_SITENAME}-someservice"
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: ${DDEV_APPROOT}
    expose:
      - "8080"
    environment:
      - VIRTUAL_HOST=$DDEV_HOSTNAME
      - HTTP_EXPOSE=8080:8080
      - HTTPS_EXPOSE=9999:8080
    volumes:
        - ".:/mnt/ddev_config"

The name of the "web" container from inside your nifi container will be "web", curl http://web:8080, assuming that you have nifi on port 8080.

I don't know what you're trying to accomplish, but this may get you started. Feel free to come over to the DDEV Discord channel for more interactive help.

huangapple
  • 本文由 发表于 2023年2月9日 02:41:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390356.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定