我在docker中运行了Python Falcon应用程序,在将其部署到弹性beantalk之前,我试图在本地工作。当我尝试连接在另一个Docker中运行的本地DynamoDB时,出现以下错误。
hayirlisi_test | Traceback (most recent call last):
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
hayirlisi_test | (self._dns_host, self.port), self.timeout, **extra_kw)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
hayirlisi_test | raise err
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 70, in create_connection
hayirlisi_test | sock.connect(sa)
hayirlisi_test | ConnectionRefusedError: [Errno 111] Connection refused
hayirlisi_test |
hayirlisi_test | During handling of the above exception, another exception occurred:
hayirlisi_test |
hayirlisi_test | Traceback (most recent call last):
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/httpsession.py", line 258, in send
hayirlisi_test | decode_content=False,
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
hayirlisi_test | _stacktrace=sys.exc_info()[2])
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 343, in increment
hayirlisi_test | raise six.reraise(type(error), error, _stacktrace)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py", line 686, in reraise
hayirlisi_test | raise value
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
hayirlisi_test | chunked=chunked)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
hayirlisi_test | conn.request(method, url, **httplib_request_kw)
hayirlisi_test | File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
hayirlisi_test | self._send_request(method, url, body, headers, encode_chunked)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/awsrequest.py", line 125, in _send_request
hayirlisi_test | method, url, body, headers, *args, **kwargs)
hayirlisi_test | File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
hayirlisi_test | self.endheaders(body, encode_chunked=encode_chunked)
hayirlisi_test | File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
hayirlisi_test | self._send_output(message_body, encode_chunked=encode_chunked)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/awsrequest.py", line 152, in _send_output
hayirlisi_test | self.send(msg)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/awsrequest.py", line 236, in send
hayirlisi_test | return super(AWSConnection, self).send(str)
hayirlisi_test | File "/usr/local/lib/python3.6/http/client.py", line 964, in send
hayirlisi_test | self.connect()
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 181, in connect
hayirlisi_test | conn = self._new_conn()
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 168, in _new_conn
hayirlisi_test | self, "Failed to establish a new connection: %s" % e)
hayirlisi_test | urllib3.exceptions.NewConnectionError: <botocore.awsrequest.AWSHTTPConnection object at 0x7fb2fd187128>: Failed to establish a new connection: [Errno 111] Connection r
efused
hayirlisi_test |
hayirlisi_test | During handling of the above exception, another exception occurred:
hayirlisi_test |
hayirlisi_test | Traceback (most recent call last):
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 135, in handle
hayirlisi_test | self.handle_request(listener, req, client, addr)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
hayirlisi_test | respiter = self.wsgi(environ, resp.start_response)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/falcon/api.py", line 244, in __call__
hayirlisi_test | responder(req, resp, **params)
hayirlisi_test | File "/code/app.py", line 54, in on_get
hayirlisi_test | 'WriteCapacityUnits': 5
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
hayirlisi_test | return self._make_api_call(operation_name, kwargs)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 648, in _make_api_call
hayirlisi_test | operation_model, request_dict, request_context)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 667, in _make_request
hayirlisi_test | return self._endpoint.make_request(operation_model, request_dict)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/endpoint.py", line 102, in make_request
hayirlisi_test | return self._send_request(request_dict, operation_model)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/endpoint.py", line 137, in _send_request
hayirlisi_test | success_response, exception):
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/endpoint.py", line 231, in _needs_retry
hayirlisi_test | caught_exception=caught_exception, request_dict=request_dict)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/hooks.py", line 356, in emit
hayirlisi_test | return self._emitter.emit(aliased_event_name, **kwargs)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/hooks.py", line 228, in emit
hayirlisi_test | return self._emit(event_name, kwargs)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/hooks.py", line 211, in _emit
hayirlisi_test | response = handler(**kwargs)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/retryhandler.py", line 183, in __call__
hayirlisi_test | if self._checker(attempts, response, caught_exception):
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/retryhandler.py", line 251, in __call__
hayirlisi_test | caught_exception)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/retryhandler.py", line 277, in _should_retry
hayirlisi_test | return self._checker(attempt_number, response, caught_exception)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/retryhandler.py", line 317, in __call__
hayirlisi_test | caught_exception)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/retryhandler.py", line 223, in __call__
hayirlisi_test | attempt_number, caught_exception)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/retryhandler.py", line 359, in _check_caught_exception
hayirlisi_test | raise caught_exception
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/endpoint.py", line 200, in _do_get_response
hayirlisi_test | http_response = self._send(request)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/endpoint.py", line 244, in _send
hayirlisi_test | return self.http_session.send(request)
hayirlisi_test | File "/usr/local/lib/python3.6/site-packages/botocore/httpsession.py", line 278, in send
hayirlisi_test | raise EndpointConnectionError(endpoint_url=request.url, error=e)
hayirlisi_test | botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "http://127.0.0.1:8000/"
我的DynamoDB变量声明看起来像这样
dynamodb = boto3.client('dynamodb', aws_access_key_id="anything",aws_secret_access_key="anything",region_name="local",endpoint_url="http://127.0.0.1:8000/%22)
我也尝试使用“ -sharedDB”参数运行DynamoDB泊坞窗。但是,我无法弄清楚自己在做什么。
答案 0 :(得分:2)
如果在两个docker容器中运行此命令,则需要完成一些操作。首先,localhost
在容器本地。也就是说,您正在调用容器的本地主机,而不是计算机的本地主机。
您将需要使其他容器彼此可见。这可以通过networks
完成。因此,您需要像这样设置:
docker network create test_network
然后,您可以像这样在该网络上运行容器:
docker run -p <host>:<container> --network=test_network -n <container_name> <image>
现在,容器中的url将是您设置的容器的name
:
myendpoint = 'http://<container_name>:<container_port>'
要查看该网络上的容器,可以运行
docker network inspect test_network
然后查看containers
部分。您将看到名称,IP地址等。要命名容器的原因是因为除非您指定名称,否则名称是随机的,与尝试通过其ip地址查找容器相比,这没有什么更好的事情< / p>