来自Docker Nameko服务器的空回复

时间:2019-04-25 14:51:23

标签: python linux bash docker curl

我已经在Docker内部设置了一个简单的nameko服务器,但是当我尝试从主机(Mac)卷曲时,我得到一个空的答复。我看了其他similar个问题,但对我来说不起作用,我得到:

$ curl http://$(echo docker-machine ip default):8080
curl: (6) Couldn't resolve host 'docker-machine'
curl: (6) Couldn't resolve host 'ip'
curl: (6) Couldn't resolve host 'default'

该问题中的OP引用了一些用户,他们向他们解释了为什么他们获得了上述帮助,但是我再也找不到该用户的评论。

在我看来,它似乎已连接,但由于某种原因,答复为空:

$curl -i localhost:8080/get/42
curl: (52) Empty reply from server

这是文件设置:

#install_anaconda.sh
#!/bin/bash
set -e
curl -O https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh
bash Anaconda3-2019.03-Linux-x86_64.sh -b
source ~/.bashrc
export PATH=~/anaconda3/bin:$PATH
conda create --name nameko --yes python=3.6 anaconda
conda update -n base -c defaults conda
source activate nameko
#Dockerfile
FROM ubuntu:latest

WORKDIR /usr/src/app

RUN apt-get update -y && apt-get install curl -y
RUN apt-get install -y python-pip python-dev build-essential 

# to install anaconda
COPY install_anaconda.sh ./
RUN ./install_anaconda.sh

COPY requirements.txt ./
RUN pip install -r requirements.txt

COPY . .

EXPOSE 8080

CMD ["nameko", "run", "email_collector"]
#email_collector.py
#!/usr/bin/env python3
import json
from nameko.web.handlers import http

class HttpService:
    name = "http_service"

    @http('GET', '/get/<int:value>')
    def get_method(self, request, value):
        return json.dumps({'value': value})

    @http('POST', '/post')
    def do_post(self, request):
        return u"received: {}".format(request.get_data(as_text=True))

    @http('GET,PUT,POST,DELETE', '/multi')
    def do_multi(self, request):
        return request.method
#requirements.txt
nameko==2.12.0

0 个答案:

没有答案