Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typing two letters at the same time causes docker exec -it shell to exit abruptly

I'm running Docker Toolbox on VirtualBox on Windows 10.

I'm having an annoying issue where if I docker exec -it mycontainer sh into a container - to inspect things, the shell will abruptly exit randomly back to the host shell, while I'm typing commands. Some experimenting reveals that it's when I press two letters at the same time (as is common when touch typing) that causes the exit.

The container will still be running.

Any ideas what this is?

More details

Here's a minimal docker image I'm running inside. Essentially, I'm trying to deploy kubernetes clusters to AWS via kops, but because I'm on Windows, I have to use a container to run the kops commands.

FROM alpine:3.5

#install aws-cli
RUN apk add --no-cache \
  bind-tools\
  python \
 python-dev \
 py-pip \
 curl


RUN pip install awscli 

#install kubectl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin/kubectl


#install kops
RUN curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
RUN chmod +x kops-linux-amd64
RUN mv kops-linux-amd64 /usr/local/bin/kops

I build this image:

docker build -t mykube . 

I run this in the working directory of my the project I'm trying to deploy:

docker run -dit -v "${PWD}":/app mykube

I exec into the shell:

docker exec -it $containerid sh 

Inside the shell, I start running AWS commands as per here.

Here's some example output:

##output of previous dig command 
;; Query time: 343 msec
;; SERVER: 10.0.2.3#53(10.0.2.3)
;; WHEN: Wed Feb 14 21:32:16 UTC 2018
;; MSG SIZE  rcvd: 188

##me entering a command
/ # aws s3 mb s3://clus
##shell exits abruptly to host shell while I'm writing
DavidJ@DavidJ-PC001 MINGW64 ~/git-workspace/webpack-react-express (master)
##container is still running 
$ docker ps --all
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
37a341cfde83        mykube              "/bin/sh"           5 minutes ago       Up 3 minutes                            gifted_bhaskara
##nothing in docker logs
$ docker logs --details 37a341cfde83

A more useful update

Adding the -D flag gives an important clue:

$ docker -D exec -it  04eef8107e91 sh -x
DEBU[0000] Error resize: Error response from daemon: no such exec
                                                                  / #
/ #
/ #
/ #
/ # sdfsdfjskfdDEBU[0006] [hijack] End of stdin
DEBU[0006] [hijack] End of stdout

Also, I've ascertained that what specifically is causing the issue is pressing two letters at the same time (which is quite common when I'm touch typing).

There appears to be a github issue for this here, though this one is for docker for windows, not docker toolbox.

like image 637
dwjohnston Avatar asked Feb 11 '18 20:02

dwjohnston


3 Answers

Check the USER which is the one you are login with when doing a docker exec -it yourContainer sh.
Its .bahsrc, .bash_profile or .profile might include a command which would explain why the session abruptly quits.

Check also the logs associated to that container (docker logs --details yourContainer) in order to see if that closed session generated anything in stderr.

like image 31
VonC Avatar answered Oct 23 '22 03:10

VonC


This issue appears to be a bug with docker and windows. See the github issue here.

As a work around, prefix your docker exec command with winpty, which comes with git bash.

eg.

winpty docker exec -it mycontainer sh
like image 136
dwjohnston Avatar answered Oct 23 '22 05:10

dwjohnston


Reasons I can think of for a process to be killed in your container include:

  • Pid 1 exiting in the container. This would cause the container to go into a stopped state, but a restart policy could have restarted it. See your docker container inspect output to see if this is happening. This is the most common cause I've seen.
  • Out of memory on the OS, where the kernel would then kill processes. View your system logs and dmesg to see if this is happening.
  • Exceeding the container memory limit, where docker would kill the container, possibly restarting it depending on your policy. You would again view docker container inspect but the status will have different details.
  • Process being killed on the host, potentially by a security tool.
  • Perhaps a selinux or apparmor policy being violated.
  • Networking issues. Never encountered it myself, but since docker is a client / server design, there's a potential for a network disconnect to drop the exec session.
  • The server itself is failing, and you'd see various logs in syslog / dmesg indicating problems it can't recover from.
like image 23
BMitch Avatar answered Oct 23 '22 03:10

BMitch