Ideally the iTDS server and transform server should have their own IP addresses. The iTDS can then proxy traffic to the transform server using the IP address of the transform server on your local network.


In some cases, you may have the transform server running on the same host machine as the iTDS, and would like to proxy transforms to "localhost".


The problem with this setup is that the Docker containers run in an isolated environment, and cannot access services running on the host machine. There are two different approaches that can be used to get around the issue. In both cases, we will follow the recommendations outline here when customizing our Docker setup.


Switch to Host Networking

It is possible to switch the servers to run using "network_mode: host" so that services running in the Docker containers can also access services running on the host machine. Switching to host networking, removes the isolated Docker network and can expose services running in the Docker container that were previously isolated.


We can create a new file "custom-itds.yml" which contains the customization needed to run the iTDS in host networking mode. The file should have the following contents:


version: '3'
services:
  itdsphp:
    network_mode: "host"

  itdsdb:
    network_mode: "host"


This will allow the iTDS to access services running on the host machine. Unfortunately this will break the communication between the "itdsphp" container and the "itdsdb" containers.


In order to fix this, you will need to add the following line to the "/etc/hosts" file on the host machine.


itdsdb localhost


This should be all the changes required to allow communication between the iTDS and a local transform server. You can run the server using the following command:


docker-compose -f itds.yml -f custom-itds.yml up


Include a Transform Server

If you would prefer to keep the default Docker bridged networking, you can add an additional "transforms" container to the docker-compose file. The iTDS will then be able to communicate directly to the transform server using the Docker networking.


We can create a new Dockerfile that will be used to build our transform server:


FROM ubuntu:18.04

RUN mkdir /var/www/
RUN mkdir /var/www/TRX/
WORKDIR /var/www/TRX/

# System dependencies
RUN apt-get update
RUN apt-get install python3-pip -y

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

# Install Gunicorn for running production server
RUN pip3 install gunicorn

COPY . /var/www/TRX/

RUN chown -R www-data:www-data /var/www/TRX/

CMD ["python", "project.py", "runserver"]


The above Dockerfile assumes that you have a local transform server project, which you want to copy and run from the /var/www/TRX/ folder.


We can create a new file "custom-itds.yml" which contains the additional service. The file should have the following contents:


version: '3'
services:
  transforms:
    build: .


This tells Docker to add an additional "transforms" container that is built using our local Dockerfile.


We can start the server using the following command:


docker-compose -f itds.yml -f custom-itds.yml up


The hostname for commincation between the iTDS and the transform server will be the same as the name of the service defined in the docker-compose file.


In this case we defined an additional service called "transforms". This means we can proxy traffic from the iTDS to the transform server using the host name "transforms".