Search code examples
dockerdocker-composeddev

Sending API-requests between two docker containers


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


Solution

  • 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.