docker container curl localhost连接被拒绝

时间:2018-12-10 09:32:34

标签: python docker

我是Docker的新手。当我尝试在容器内卷曲localhost时,我无法连接到localhost端口9922:连接被拒绝

我看到了一个Mac的答案,该答案是将docker.for.mac.localhost 替换为适用于我的Mac的localhost。但是ubuntu呢?

这是详细信息:

Docker文件:

# Use an official Python runtime as a parent image
FROM python:3.7-slim

# Set up working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Make port 5000 available to the world outside this container
EXPOSE 5000

#Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "app.py"]

requirements.txt:

numpy
pandas
setuptools
pytest
apscheduler
flask
bokeh
google-api-python-client
google-auth
google-auth-httplib2
oauth2client
tqdm
bs4
tabulate
seaborn
matplotlib
requests

在我的代码内:

url = 'http://docker.for.mac.localhost:9922'
# url = 'http://localhost:9922'

Docker命令:

$ docker run --rm -it -p 5000:5000 --name wallet <name-of-image>

以上,如果我使用 url ='http://docker.for.mac.localhost:9922',则效果很好。但是 url ='http://localhost:9922'不起作用。外部Docker容器 url ='http://localhost:9922'将起作用。所以这是我的问题:如果我在ubuntu上运行此docker映像,应该使用什么访问本地主机? url ='http://docker.for.ubuntu.localhost:9922'之类的东西?

0 个答案:

没有答案