Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active December 14, 2017 15:39
Show Gist options
  • Save stevewithington/4daf5562fe2b0e0e88450f142faf0282 to your computer and use it in GitHub Desktop.
Save stevewithington/4daf5562fe2b0e0e88450f142faf0282 to your computer and use it in GitHub Desktop.
ColdFusion (CFML) Localhost CFHTTP Call Inside of Docker on MacOSX

There's an issue when attempting to perform a cfhttp call inside of Docker to localhost on MacOSX. For some reason, this issue does not appear to exist on Windows. Instead of hitting localhost, you must use the "Service Name" as defined in your docker-compose.yml file, and the container's exposed port (NOT the one you're using outside of the container).

Example docker-compose.yml

version: '3.3'
  services:
    myservice:
      build:
        context: .
      image: some-image
      depends_on:
        - svc_someservice
      environment:
        # blah
      volumes:
        - ./www:/app
      ports:
        - '80:8080'
      # etc.

In the example above, our service is named myservice, and the exposed port is 8080. So, to make a cfhttp call, you would have to format your URL as http://myservice:8080/some/path/. This would result in the following examples:

CFScript (CF9+)

svcHttp = new http(method='GET', charset='utf-8', url='http://myservice:8080/some/path/');
svcHttp.addParam(name='q', type='formfield', value='somevalue');
result = svcHttp.send().getPrefix();
WriteDump(result);

CFScript (CF11+)

cfhttp(method='GET', charset='utf-8', url='http://myservice:8080/some/path/', result='result') {
  cfhttpparam(name='q', type='formfield', value='somevalue');
}
WriteDump(result);

CFHTTP Tag Syntax

<cfhttp method="GET" charset="utf-8" url="http://myservice:8080/some/path/" result="result">
  <cfhttpparam name="q" type="formfield" value="somevalue" />
</cfhttp>
<cfdump var="#result#" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment