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
7-gdb-show prompt
~"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"
~"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="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"
~"TERM = xterm-256color\n"
&"$PWD: No such file or directory.\n"
&"agentgtest: No such file or directory.\n"
6^error,msg="No symbol table is loaded.  Use the \"file\" command."
7^done,value="(gdb) "
8^error,msg="No registers."

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