[英]Container is unreachable from up services when using docker-compose run
I have a docker-compose config like the following: 我有一个类似docker-compose的配置:
version: '3.7'
services:
flask:
command: [python, app.py]
ports:
- "127.0.0.1:5000:5000"
frontend:
command: [sh, -c, "npm run start"]
ports:
- "127.0.0.1:7600:7600"
links:
- flask
The frontend
container has a webpack development server running which proxies /api/*
path requests to flask:5000
for processing. frontend
容器运行着一个webpack开发服务器,该服务器将/api/*
路径请求代理到flask:5000
进行处理。 This works great when I use docker-compose up -d
. 当我使用docker-compose up -d
时,这很好用。
However, let's say I want to debug something in the flask app using pdb
, and I run it manually instead using: 但是,假设我想使用pdb
在flask应用程序中调试某些内容,而是使用以下命令手动运行它:
docker-compose stop flask
docker-compose run --rm --service-ports flask python app.py
Then suddenly, my frontend
service cannot proxy request to my flask
service and I'm getting an error like: Error occurred while trying to proxy request /testing from frontend:7600 to http://flask:5000 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
然后突然,我的frontend
服务无法将请求代理到我的flask
服务,并且出现了如下Error occurred while trying to proxy request /testing from frontend:7600 to http://flask:5000 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
: Error occurred while trying to proxy request /testing from frontend:7600 to http://flask:5000 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
What am I missing? 我想念什么? How do I make this configuration work for interactive debugging of my python code? 如何使此配置适用于python代码的交互式调试?
Edit: I'm running Docker version 18.09.0, build 4d60db4
and docker-compose version 1.23.2, build 1110ad01
编辑:我正在运行Docker version 18.09.0, build 4d60db4
和Docker version 18.09.0, build 4d60db4
docker-compose version 1.23.2, build 1110ad01
The problem is when you run manually, the container name is no longer flask
, you can see that with docker network inspect your_network
. 问题是,当您手动运行时,容器名称不再是flask
,您可以看到在docker network inspect your_network
。
You need to first docker-compose rm flask
to free the name flask
, then docker-compose run --service-ports --name flask flask
. 您需要首先docker-compose rm flask
释放名称flask
,然后docker-compose run --service-ports --name flask flask
。
Finally, I don't know how you use pdb
, but you can normally use docker-compose exec flask sh
or docker attach container_id
to get an interactive prompt. 最后,我不知道如何使用pdb
,但是通常可以使用docker-compose exec flask sh
或docker attach container_id
来获取交互式提示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.