Connection timed out when attaching to Docker via Websocket

Currently I’m trying to remotely run bash commands in a container by attaching via Websocket, like this:

new WebSocket('ws://172.24.0.2:2375/containers/0df8ba74d96f/attach/ws?stdin=1&stdout=1&stderr=1&stream=1')

and the connection is timed out. I have also tested with using the browser and Node (using third party websocket library) and both return the same error. According to the docs, this is how I should go about connecting. Any advice?