python - docker 容器 curl localhost 连接被拒绝 ubuntu
问题描述
我是码头工人的新手。当我尝试在容器内卷曲 localhost 时,出现Failed to connect to localhost port 9922: Connection refused。
我看到了一个 mac 的答案,用 docker.for.mac.localhost 替换 localhost这适用于我的 mac。但是ubuntu呢?
这是详细信息:
码头工人文件:
# 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"]
要求.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 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 映像,我应该使用什么来访问 localhost?像url = ' http://docker.for.ubuntu.localhost:9922 ' 之类的东西?
解决方案
推荐阅读
- android - 无法从资产“index.android.bundle”加载脚本,请确保您的捆绑包已打包
- sql - 动态生成视图名称的拖放视图语法
- php - 在 codeigniter 中使用 $this 时不在对象上下文中
- java - 比较 url 字符串的路径。忽略域名
- javascript - ChartJS:设置图表加载时显示哪些数据并保存(记住)它
- jquery - 在发出请求之前覆盖 ajax 请求以更改 url
- javascript - 如何创建具有函数返回结果的数组?
- vba - 从展开/折叠数据透视表中提取“隐藏”数据 - Excel
- javascript - Lodash:提取属性,拆分数组,获取唯一值
- spring-boot - 如何在 Jhipster-gateway 上为微服务添加不同的速率限制