Docker names的空回复

2024-04-23 17:15:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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

Tags: installrunhttphostgetbinvaluerequest