Запуск Docker внутри приложения Python на Heroku?

#python #docker #heroku

#python #docker #heroku

Вопрос:

Я использую Docker SDK для Python, и следующий код работает должным образом локально:

 import docker
client = docker.from_env()
output = client.containers.run(image="python:3.6.0", command=["redacted"], remove=True)
  

Я добавил docker в свой Heroku requirements.txt файл, но Heroku не может подключиться к Docker. Трассировка стека — это в основном проблемы с подключением:

 2020-08-13T08:12:50.572249 00:00 app[web.1]: Traceback (most recent call last):
2020-08-13T08:12:50.572307 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
2020-08-13T08:12:50.572308 00:00 app[web.1]: chunked=chunked,
2020-08-13T08:12:50.572308 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 392, in _make_request
2020-08-13T08:12:50.572309 00:00 app[web.1]: conn.request(method, url, **httplib_request_kw)
2020-08-13T08:12:50.572310 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1229, in request
2020-08-13T08:12:50.572310 00:00 app[web.1]: self._send_request(method, url, body, headers, encode_chunked)
2020-08-13T08:12:50.572310 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1275, in _send_request
2020-08-13T08:12:50.572311 00:00 app[web.1]: self.endheaders(body, encode_chunked=encode_chunked)
2020-08-13T08:12:50.572311 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1224, in endheaders
2020-08-13T08:12:50.572312 00:00 app[web.1]: self._send_output(message_body, encode_chunked=encode_chunked)
2020-08-13T08:12:50.572312 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1016, in _send_output
2020-08-13T08:12:50.572312 00:00 app[web.1]: self.send(msg)
2020-08-13T08:12:50.572312 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 956, in send
2020-08-13T08:12:50.572313 00:00 app[web.1]: self.connect()
2020-08-13T08:12:50.572313 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/docker/transport/unixconn.py", line 43, in connect
2020-08-13T08:12:50.572313 00:00 app[web.1]: sock.connect(self.unix_socket)
2020-08-13T08:12:50.572314 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gevent/_socket3.py", line 356, in connect
2020-08-13T08:12:50.572314 00:00 app[web.1]: raise error(result, strerror(result))
2020-08-13T08:12:50.572314 00:00 app[web.1]: FileNotFoundError: [Errno 2] No such file or directory
2020-08-13T08:12:50.572314 00:00 app[web.1]: 
2020-08-13T08:12:50.572315 00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-08-13T08:12:50.572315 00:00 app[web.1]: 
2020-08-13T08:12:50.572315 00:00 app[web.1]: Traceback (most recent call last):
2020-08-13T08:12:50.572315 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
2020-08-13T08:12:50.572315 00:00 app[web.1]: timeout=timeout
2020-08-13T08:12:50.572316 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 727, in urlopen
2020-08-13T08:12:50.572316 00:00 app[web.1]: method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
2020-08-13T08:12:50.572316 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/util/retry.py", line 403, in increment
2020-08-13T08:12:50.572316 00:00 app[web.1]: raise six.reraise(type(error), error, _stacktrace)
2020-08-13T08:12:50.572316 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
2020-08-13T08:12:50.572317 00:00 app[web.1]: raise value.with_traceback(tb)
2020-08-13T08:12:50.572317 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
2020-08-13T08:12:50.572317 00:00 app[web.1]: chunked=chunked,
2020-08-13T08:12:50.572317 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 392, in _make_request
2020-08-13T08:12:50.572318 00:00 app[web.1]: conn.request(method, url, **httplib_request_kw)
2020-08-13T08:12:50.572318 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1229, in request
2020-08-13T08:12:50.572318 00:00 app[web.1]: self._send_request(method, url, body, headers, encode_chunked)
2020-08-13T08:12:50.572318 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1275, in _send_request
2020-08-13T08:12:50.572318 00:00 app[web.1]: self.endheaders(body, encode_chunked=encode_chunked)
2020-08-13T08:12:50.572319 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1224, in endheaders
2020-08-13T08:12:50.572319 00:00 app[web.1]: self._send_output(message_body, encode_chunked=encode_chunked)
2020-08-13T08:12:50.572319 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 1016, in _send_output
2020-08-13T08:12:50.572319 00:00 app[web.1]: self.send(msg)
2020-08-13T08:12:50.572319 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/http/client.py", line 956, in send
2020-08-13T08:12:50.572320 00:00 app[web.1]: self.connect()
2020-08-13T08:12:50.572320 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/docker/transport/unixconn.py", line 43, in connect
2020-08-13T08:12:50.572320 00:00 app[web.1]: sock.connect(self.unix_socket)
2020-08-13T08:12:50.572320 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gevent/_socket3.py", line 356, in connect
2020-08-13T08:12:50.572320 00:00 app[web.1]: raise error(result, strerror(result))
2020-08-13T08:12:50.572320 00:00 app[web.1]: urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
2020-08-13T08:12:50.572321 00:00 app[web.1]: 
2020-08-13T08:12:50.572321 00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-08-13T08:12:50.572321 00:00 app[web.1]: 
2020-08-13T08:12:50.572321 00:00 app[web.1]: Traceback (most recent call last):
2020-08-13T08:12:50.572321 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/bottle.py", line 862, in _handle
2020-08-13T08:12:50.572321 00:00 app[web.1]: return route.call(**args)
2020-08-13T08:12:50.572322 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/bottle.py", line 1740, in wrapper
2020-08-13T08:12:50.572322 00:00 app[web.1]: rv = callback(*a, **ka)

2020-08-13T08:12:50.572340 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/docker/models/containers.py", line 868, in create
2020-08-13T08:12:50.572340 00:00 app[web.1]: resp = self.client.api.create_container(**create_kwargs)
2020-08-13T08:12:50.572340 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/docker/api/container.py", line 430, in create_container
2020-08-13T08:12:50.572341 00:00 app[web.1]: return self.create_container_from_config(config, name)
2020-08-13T08:12:50.572341 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/docker/api/container.py", line 440, in create_container_from_config
2020-08-13T08:12:50.572341 00:00 app[web.1]: res = self._post_json(u, data=config, params=params)
2020-08-13T08:12:50.572341 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/docker/api/client.py", line 289, in _post_json
2020-08-13T08:12:50.572342 00:00 app[web.1]: return self._post(url, data=json.dumps(data2), **kwargs)
2020-08-13T08:12:50.572342 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/docker/utils/decorators.py", line 46, in inner
2020-08-13T08:12:50.572342 00:00 app[web.1]: return f(self, *args, **kwargs)
2020-08-13T08:12:50.572342 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/docker/api/client.py", line 226, in _post
2020-08-13T08:12:50.572343 00:00 app[web.1]: return self.post(url, **self._set_request_timeout(kwargs))
2020-08-13T08:12:50.572343 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/sessions.py", line 578, in post
2020-08-13T08:12:50.572343 00:00 app[web.1]: return self.request('POST', url, data=data, json=json, **kwargs)
2020-08-13T08:12:50.572343 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
2020-08-13T08:12:50.572343 00:00 app[web.1]: resp = self.send(prep, **send_kwargs)
2020-08-13T08:12:50.572344 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
2020-08-13T08:12:50.572344 00:00 app[web.1]: r = adapter.send(request, **kwargs)
2020-08-13T08:12:50.572344 00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
2020-08-13T08:12:50.572345 00:00 app[web.1]: raise ConnectionError(err, request=request)
2020-08-13T08:12:50.572345 00:00 app[web.1]: requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
  

Как я могу запустить Docker внутри приложения Python на Heroku? У кого-нибудь был успех с этим?