Emacs gud mode fails with docker gdb

I’m using “GNU Emacs 25.1.1 (x86_64-pc-linux-gnu, GTK+ Version
3.22.11) of 2017-03-29, modified by Debian” on ubuntu zesty on an
Intel Xeon.

I have a docker image (with ubuntu xenial), “Docker version
17.06.1-ce, build 874a737”, in which I’m trying to run gdb. The emacs
is running outside the docker while gdb is running inside the docker.
The docker container is called “xenial-3.0.0”. I start gdb with M-x
gdb and a command line of:

docker exec -it xenial-3.0.0 gdb -i=mi -cd=$PWD agentgtest

The bug is that I’m getting the message:

Error: you did not specify -i=mi on GDB's command line!

I’ve set (setq gdbmi-debug-mode t) and Messages contains:

...
gdb-input: 1-inferior-tty-set /dev/pts/6
gdb-input: 2-gdb-set height 0
gdb-input: 3-gdb-set non-stop 1
gdb-input: 4-enable-pretty-printing
gdb-input: 5-file-list-exec-source-files
gdb-input: 6-file-list-exec-source-file
gdb-input: 7-gdb-show prompt
gdb-input: 8-stack-info-frame
gdb-input: 9-thread-info
gdb-input: 10-break-list
gdb-input: 11-thread-info
gdb-input: 12-break-list
Error: you did not specify -i=mi on GDB’s command line!
C-h C-g is undefined
Updating buffer list...done
Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help
...

The gud-exec buffer contains:

Current directory is /home/mecklen/c4software/3.0.0/control4/zwave/agent/gtest/
Error: you did not specify -i=mi on GDB's command line!
1-inferior-tty-set /dev/pts/6
2-gdb-set height 0
3-gdb-set non-stop 1
4-enable-pretty-printing
5-file-list-exec-source-files
6-file-list-exec-source-file
7-gdb-show prompt
8-stack-info-frame
9-thread-info
10-break-list
11-thread-info
12-break-list
=thread-group-added,id="i1"
~"GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1\n"
~"Copyright (C) 2016 Free Software Foundation, Inc.\n"
~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\n"
~"This GDB was configured as \"x86_64-linux-gnu\".\nType \"show configuration\" for configuration details."
~"\nFor bug reporting instructions, please see:\n"
~"<http://www.gnu.org/software/gdb/bugs/>.\n"
~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n"
~"For help, type \"help\".\n"
~"Type \"apropos word\" to search for commands related to \"word\"...\n"
=cmd-param-changed,param="demangle-style",value="gnu-v3"
=cmd-param-changed,param="print array",value="on"
=cmd-param-changed,param="print elements",value="20000"
=cmd-param-changed,param="print object",value="on"
=cmd-param-changed,param="print pretty",value="on"
=cmd-param-changed,param="print static-members",value="off"
=cmd-param-changed,param="print vtbl",value="on"
=cmd-param-changed,param="mi-async",value="on"
=cmd-param-changed,param="pagination",value="off"
~"TERM = xterm-256color\n"
&"$PWD: No such file or directory.\n"
&"agentgtest: No such file or directory.\n"
(gdb) 
1^done
(gdb) 
2^done
(gdb) 
3^done
(gdb) 
4^done
(gdb) 
5^done,files=[]
(gdb) 
6^error,msg="No symbol table is loaded.  Use the \"file\" command."
(gdb) 
7^done,value="(gdb) "
(gdb) 
8^error,msg="No registers."
(gdb) 
9^done,threads=[]
(gdb) 
10^done,BreakpointTable={nr_rows="0",nr_cols="6",hdr=[{width="7",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[]}
(gdb) 
11^done,threads=[]
(gdb) 
12^done,BreakpointTable={nr_rows="0",nr_cols="6",hdr=[{width="7",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[]}
(gdb)

The original docker image was run with:

docker run --interactive --tty \
--volume /home/mecklen:/home/mecklen \
--hostname xenial-3.0.0 \
--name xenial-3.0.0 \
--security-opt seccomp:unconfined \
xenial-3.0.0-builder /bin/bash

It seems as if the initial sequence of mi control commands is somehow
being echoed back to emacs and processed as input. That makes no
sense to me, any suggestions are welcome.

BTW, I’m familiar with accessing a docker from TRAMP and using M-x gdb
that way. I works a little better but has a different set of issues
and I’d prefer to use this approach, if possible.

Thanks in advance,
Robert Mecklenburg
rmecklenburg@control4.com