From 2806d9bf8547869d7cba08173d5b1688ce56e853 Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Fri, 29 Sep 2017 16:09:42 +0200 Subject: [PATCH] specify API version in url used to open the websocket. With version 1.28 and up, docker uses binary frame format for websockets which does not seem to work with FAYE websocket. For API version 1.27 and below, text frame format is used. + short fix improvement for empty responses --- lib/docker_client.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/docker_client.rb b/lib/docker_client.rb index 76451096..add507ba 100644 --- a/lib/docker_client.rb +++ b/lib/docker_client.rb @@ -72,7 +72,7 @@ class DockerClient # Headers are required by Docker headers = {'Origin' => 'http://localhost'} - socket_url = DockerClient.config['ws_host'] + '/containers/' + @container.id + '/attach/ws?' + query_params + socket_url = DockerClient.config['ws_host'] + '/v1.27/containers/' + @container.id + '/attach/ws?' + query_params socket = Faye::WebSocket::Client.new(socket_url, [], :headers => headers) Rails.logger.debug "Opening Websocket on URL " + socket_url @@ -399,6 +399,9 @@ class DockerClient output = container.exec(['bash', '-c', command]) Rails.logger.debug "output from container.exec" Rails.logger.debug output + if(output == nil) + kill_container(container) + end result = {status: output[2] == 0 ? :ok : :failed, stdout: output[0].join.force_encoding('utf-8'), stderr: output[1].join.force_encoding('utf-8')} end # if we use pooling and recylce the containers, put it back. otherwise, destroy it.