[英]Docker connection refused hanging Django
When I run my container, it just hangs on the next line and if I write当我运行我的容器时,它只是挂在下一行,如果我写
I get我得到
Failed to connect to 0.0.0.0 port 8000: Connection refuse
无法连接到 0.0.0.0 端口 8000:连接拒绝
This is my dockerfile这是我的 dockerfile
FROM python:3.6.1
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
RUN pip3 install -r requirements.txt
CMD ["python3", "dockerizing/manage.py", "runserver", "0.0.0.0:8000"]
I also tried doing it through a docker-compose.yml file and again nothing happens, I´ve searched a lot and haven´t found a solution, this is the docker-compose.yml我还尝试通过 docker-compose.yml 文件进行操作,但没有任何反应,我搜索了很多但没有找到解决方案,这是 docker-compose.yml
version: "3"
services:
web:
image: app1
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "8000:8000"
networks:
- webnet
networks:
webnet:
By the way, if I run docker ps with myapp image I get this:顺便说一句,如果我用 myapp 图像运行 docker ps 我得到这个:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e9633657f060 app1 "python3 dockerizi..." 5 seconds ago Up 5 seconds friendly_dijkstra
When I deploy the service with the django-compose.yml and docker ps
I get this:当我使用 django-compose.yml 和 docker
docker ps
部署服务时,我得到了这个:
`MacBook-Pro-de-Jesus:docker-django Almaral$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
13677a71d9d5 app1:latest "python3 dockerizin..." 15 seconds ago Up 11 seconds getstartedlab_web.1.cq3zqmpfsii5g6m5r9qsnmtb1
c6693118ef70 app1:latest "python3 dockerizin..." 16 seconds ago Up 12 seconds getstartedlab_web.4.r472oh80s4zd1yymj447f1df6
f3822e47970b app1:latest "python3 dockerizin..." 16 seconds ago Up 12 seconds getstartedlab_web.2.lkp43v9h30esjohcnf3pe31hi
f66a4038ebdf app1:latest "python3 dockerizin..." 16 seconds ago Up 12 seconds getstartedlab_web.5.xxu01ruebd84tnlxmoymsu0vo
e3d31c419c11 app1:latest "python3 dockerizin..." 16 seconds ago Up 13 seconds getstartedlab_web.3.uqswgirmg22sjnekzmf5b4xo7`
Your docker ps
output shows nothing in the PORTS column.您的
docker ps
输出在 PORTS 列中没有显示任何内容。 That means that there's no port forwarding from the host to the container.这意味着没有从主机到容器的端口转发。
[...] STATUS PORTS NAMES
[...] Up 5 seconds friendly_dijkstra
If you use the command docker run
to run your container, you should explicitly specify port number both on host and on the container using the command option -p hostPort:containerPort
如果您使用命令
docker run
来运行您的容器,您应该使用命令选项-p hostPort:containerPort
在主机和容器上明确指定端口号
docker run -p 8000:8000 app1
Now, running docker ps
should show port forwarding.现在,运行
docker ps
应该会显示端口转发。
[...] STATUS PORTS NAMES
[...] Up 5 seconds 0.0.0.0:8000->8000/tcp friendly_dijkstra
If you are using docker-compose
to start your containers, the host and container ports are already configured in your docker-compose.yml file, so you don't need a command line option.如果您使用
docker-compose
启动容器,则主机和容器端口已在 docker-compose.yml 文件中配置,因此您不需要命令行选项。
docker-compose up web
To use docker compose, you have to install it on the host.要使用 docker compose,您必须在主机上安装它。 It's a python module, so you can install it with pip
pip install docker-compose
这是一个 python 模块,所以你可以用 pip
pip install docker-compose
安装它
进入您的 docker-compose 配置文件,将您的端口重定向从: 8000:8000
修改为127.0.0.1:8000:8000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.