<p dir="auto">During writing container attach node e2e test, I found this.</p>
<p dir="auto">Docker attach has an option called <code class="notranslate">Logs</code> (see <a href="https://docs.docker.com/engine/reference/api/docker_remote_api_v1.22/#attach-to-a-container" rel="nofollow">Docker Remote API</a>).<br>
With this on, before each container attach docker will print the container log first (see <a href="https://github.com/docker/docker/blob/5709f8e4227e0e1da333739c44003a3f47279bd5/daemon/attach.go#L77-L106">code</a>)</p>
<p dir="auto">The <code class="notranslate">Logs</code> option is supported in go-dockerclient (see <a href="https://github.com/fsouza/go-dockerclient/blob/master/container.go#L1127">code</a>), while it is not supported in engine-api yet (see <a href="https://github.com/docker/engine-api/blob/8924d6900370b4c7e7984be5adc61f50a80d7537/types/client.go#L14-L21">code</a>).</p>
<p dir="auto">Before <a href="#23506">switching to engine-api</a>, the <code class="notranslate">Logs</code> option is <strong>true</strong> (see <a href="https://github.com/kubernetes/kubernetes/blob/release-1.2/pkg/kubelet/dockertools/manager.go#L1115">old code</a>). While because engine-api doesn't support it, we don't set it now (see <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/dockertools/kube_docker_client.go#L324-L331">code</a>)</p>
<p dir="auto">What is the expected behavior here? If needed, we could send a PR to engine-api to support it.</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ncdc/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ncdc">@ncdc</a></p>
<p dir="auto">/cc @kubernetes/sig-node @kubernetes/rh-ux</p>
<p dir="auto">Ref <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="144114383" data-permission-text="Title is private" data-url="https://github.com/kubernetes/kubernetes/issues/23563" data-hovercard-type="issue" data-hovercard-url="/kubernetes/kubernetes/issues/23563/hovercard" href="https://github.com/kubernetes/kubernetes/issues/23563">#23563</a></p>
<p dir="auto">When running a command via <code class="notranslate">kubectl run -it</code> that immediately prints something, we might lose some lines of the log due to a race of the execution of the container and the <code class="notranslate">kubectl attach</code> used by <code class="notranslate">kubectl run</code> to attach to the terminal (compare comment <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="114629913" data-permission-text="Title is private" data-url="https://github.com/kubernetes/kubernetes/issues/16670" data-hovercard-type="issue" data-hovercard-url="/kubernetes/kubernetes/issues/16670/hovercard?comment_id=199017681&amp;comment_type=issue_comment" href="https://github.com/kubernetes/kubernetes/issues/16670#issuecomment-199017681">#16670 (comment)</a>).</p>
<p dir="auto">As a workaround for running an interactive shell we have this ugly <code class="notranslate">Hit enter for command prompt</code> now. The actual root problem though is that <code class="notranslate">docker attach</code> does not replay the logs. It looks like <code class="notranslate">docker run</code> is the only way to actually synchronously run a command, get all the output and attach to the process.</p>