简体   繁体   中英

How do I run a docker-compose container in interactive mode such that other containers see it?

The scenario: I set a breakpoint in code, which is mounted (as a volume) into a container, created by docker-compose. The code is an odoo module, so it's part of the odoo container.

There is also a webapp container, which has a link to odoo in order to use the API.

The odoo container doesn't expose the API port because the host doesn't need it; the webapp container can, of course, see it.

services:
  odoo:
    volumes:
      - localpath:/mnt/extra-addons-bundles
  webapp:
    links:
      - odoo

Of course, the purpose of the breakpoint is to allow me to control the application - so I need a TTY attached. I can do this with docker-compose run --rm odoo . However, when I do this, it creates a new container, so the webapp never actually hits it. Plus, it doesn't tell me what the new container is called, so I have to manually figure it out to do that.

I can use docker exec to run another odoo in the odoo container but then I have to run it on a new port, and thus change the webapp config to use this new instance.

Is there a way of achieving what I want, ie to run the odoo container in interactive mode, such that the webapp container can see it, and without reconfiguring the webapp container?

Try this and see if it works

services:
  odoo:
    volumes:
      - localpath:/mnt/extra-addons-bundles
    tty: true
    stdin_open: true
  webapp:
    links:
      - odoo

I have also added stdin_open in case you need it, if you don't just remove it

Edit-1

Also if you need to attach to the running container, then you need to use docker attach as docker-compose doesn't have that functionality

docker attach <containername>

答案是在docker-compose文件中使用tty: true ,然后使用docker attach将该进程实际附加到您的终端。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM