我是码头 Worker 的新手 . 当我试图在容器内卷曲localhost时,我得到 Failed to connect to localhost port 9922: Connection refused .

我看到mac的答案是 replace localhost with docker.for.mac.localhost ,它适用于我的mac . 但是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' 将无效 . 外码头集装箱 url = 'http://localhost:9922' 将起作用 . 所以这是我的问题:如果我在ubuntu上运行这个docker镜像我应该用什么来访问localhost?像 url = 'http://docker.for.ubuntu.localhost:9922' 这样的东西?