简体   繁体   English

使用docker-compose run时,容器无法通过启动服务访问

[英]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 4d60db4Docker 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 shdocker attach container_id来获取交互式提示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用docker-compose up与docker-compose run从容器内部执行容器中的命令 - executing commands in containers from within a container using docker-compose up vs docker-compose run 从 docker-compose 运行时容器以代码 0 退出 - Container exited with code 0 when run from docker-compose 当使用 docker-compose 'command:' 运行时,Supervisord 在 Docker 容器内退出,但从 bash 运行时不会退出 - Supervisord exits inside Docker container when run with docker-compose 'command:', but not when its run from bash 容器不停留在docker-compose up上 - Container not staying up on docker-compose up 当用docker-compose run调用但gunicorn可以工作,但不能通过docker-compose up调用 - gunicorn works when called with docker-compose run but not docker-compose up 如何以与 docker-compose 相同的方式在远程服务器上运行 Docker 容器? - How can I run a Docker container on a remote server in the same manner as docker-compose up? KeyError:从 Fabric 运行 docker-compose up 时出现“PATH” - KeyError: 'PATH' when running docker-compose up from Fabric 运行 docker-compose 时如何将参数传递给 docker 容器 - How to pass argument to docker container when running docker-compose up Docker 无法打开文件以在使用 django 的容器中运行 python 应用程序,使用 ZBAEDB53E845AE71F13945FCC00572 - Docker can't open file to run the python application in a container with django using docker-compose 无法从 docker-compose 的另一个容器访问 api 的 docker 容器 - docker container of api not accessible from another container of docker-compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM