# Integration in docker-compose

**URL:** https://discourse.mitmproxy.org/t/integration-in-docker-compose/996
**Category:** help
**Created:** [April 19, 2018, 9:55am UTC](https://discourse.mitmproxy.org/t/integration-in-docker-compose/996 "2018-04-19T09:55:56Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![boubasse](https://avatars.discourse-cdn.com/v4/letter/b/ce73a5/32.png) [@boubasse](https://discourse.mitmproxy.org/u/boubasse)
#### Post date: [April 19, 2018, 9:55am UTC](https://discourse.mitmproxy.org/t/integration-in-docker-compose/996/1 "2018-04-19T09:55:56Z")

</div>

Hello,

I’m trying to launch a mitmproxy container with docker-compose but it always fails even with the tty: true parameter.

My docker-compose.yml is like :

```auto
version: '3'
  services:
    mitmproxy:
      image: "mitmproxy/mitmproxy"
      container_name: "mitmproxy"
      ports:
        - 8080:8080
      tty: true

```

But everytime I launch “docker-compose up -d”, the mitmproxy container crashes instantly.

Here are the logs about the crash :

```auto
Traceback (most recent call last):
  File "/usr/bin/mitmproxy", line 11, in <module>
    sys.exit(mitmproxy())
  File "/usr/lib/python3.6/site-packages/mitmproxy/tools/main.py", line 140, in mitmproxy
    run(console.master.ConsoleMaster, cmdline.mitmproxy, args)
  File "/usr/lib/python3.6/site-packages/mitmproxy/tools/main.py", line 122, in run
    master.run()
  File "/usr/lib/python3.6/site-packages/mitmproxy/tools/console/master.py", line 213, in run
    self.window = window.Window(self)
  File "/usr/lib/python3.6/site-packages/mitmproxy/tools/console/window.py", line 149, in __init__
    WindowStack(master, "flowlist"),
  File "/usr/lib/python3.6/site-packages/mitmproxy/tools/console/window.py", line 57, in __init__
    commands = commands.Commands(master),
  File "/usr/lib/python3.6/site-packages/mitmproxy/tools/console/commands.py", line 131, in __init__
    oh = CommandHelp(master)
  File "/usr/lib/python3.6/site-packages/mitmproxy/tools/console/commands.py", line 107, in __init__
    super(). __init__ (self.widget(""))
  File "/usr/lib/python3.6/site-packages/mitmproxy/tools/console/commands.py", line 119, in widget
    [urwid.Text(i) for i in textwrap.wrap(txt, cols)]
  File "/usr/lib/python3.6/textwrap.py", line 379, in wrap
    return w.wrap(text)
  File "/usr/lib/python3.6/textwrap.py", line 354, in wrap
    return self._wrap_chunks(chunks)
  File "/usr/lib/python3.6/textwrap.py", line 248, in _wrap_chunks
    raise ValueError("invalid width %r (must be > 0)" % self.width)
ValueError: invalid width 0 (must be > 0)

```

Is there a solution to that problem ?

Thanks for your answers

---

<div class="post-metadata">

### Author: ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)
#### Post date: [April 25, 2018, 2:26pm UTC](https://discourse.mitmproxy.org/t/integration-in-docker-compose/996/2 "2018-04-25T14:26:16Z")

</div>

Hi,

is there a particular reason why you want to run mitmproxy via docker-compose and not mitmdump? The problem here seems to be that we spawn in a shell with width 0, which we don’t handle properly.

---

<div class="post-metadata">

### Author: ![boubasse](https://avatars.discourse-cdn.com/v4/letter/b/ce73a5/32.png) [@boubasse](https://discourse.mitmproxy.org/u/boubasse)
#### Post date: [April 27, 2018, 8:42am UTC](https://discourse.mitmproxy.org/t/integration-in-docker-compose/996/3 "2018-04-27T08:42:03Z")

</div>

Hi,

I want to run mitmproxy via docker-compose to see HTTP streams directly. Mitmdump doesn’t have the same features (inspecting request and response on the air). Do you have a solution for this ?

---

<div class="post-metadata">

### Author: ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)
#### Post date: [May 16, 2018, 12:49pm UTC](https://discourse.mitmproxy.org/t/integration-in-docker-compose/996/4 "2018-05-16T12:49:53Z")

</div>

No idea, this not really is a mitmproxy issue: [https://github.com/moby/moby/issues/33794](https://github.com/moby/moby/issues/33794)

---

<div class="post-metadata">

### Author: ![shobble](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@shobble](https://discourse.mitmproxy.org/u/shobble)
#### Post date: [May 23, 2018, 4:20pm UTC](https://discourse.mitmproxy.org/t/integration-in-docker-compose/996/5 "2018-05-23T16:20:12Z")

</div>

I’ve managed to make it mostly work with something like the following:

```auto
    mtest:
        image: mitmproxy/mitmproxy
        entrypoint: '/bin/sh -c "stty rows 24 cols 80 && mitmproxy -p8080 --mode reverse:http://thingy:8080/"'
        tty: true
        stdin_open: true

```

caveats: you’ll need to start it in detached mode (`docker-compose up -d ...`)

and there doesn’t seem be a compose command for actually attaching to it afterwards, you need to use the `docker attach <full_container_name>` variant instead.

You can detach without killing the running proxy with ctrl-p,ctrl-q by default (although that appears to be sometimes forcing a stop, possibly it’s getting confused with tty flow control if docker is passing the ctrl-q onto it.

I’d just use `docker attach --detach-keys ctrl-x,ctrl-x $CONTAINER` instead and find a bind that isn’t taken.

---

<div class="post-metadata">

### Author: ![boubasse](https://avatars.discourse-cdn.com/v4/letter/b/ce73a5/32.png) [@boubasse](https://discourse.mitmproxy.org/u/boubasse)
#### Post date: [May 24, 2018, 9:02am UTC](https://discourse.mitmproxy.org/t/integration-in-docker-compose/996/6 "2018-05-24T09:02:27Z")

</div>

Finally, I’ve found a way to open the tty with stdin.

Just need to declare tty, stdin\_open and container\_name in the compose file.

Then when you start the containers with `docker-compose up -d`, the container will stop since there is no tty to attach to.

Then you just need to run `docker start -i <container_name>` and you will have the tty for mitmproxy with stdin enabled.
