Skip to content

Instantly share code, notes, and snippets.

@ptrj
Created October 5, 2018 15:34
Show Gist options
  • Save ptrj/b54b8cdd34f632028e669a1e71bc03b8 to your computer and use it in GitHub Desktop.
Save ptrj/b54b8cdd34f632028e669a1e71bc03b8 to your computer and use it in GitHub Desktop.
tmux in demonized docker container

tmux in demonized docker container

Dockerfile

FROM ubuntu:16.04

ENV DEBIAN_FRONTEND noninteractive
ENV TERM xterm
RUN dpkg --add-architecture i386 && \
    apt-get update -y && \
    apt-get install -y tmux

COPY start.sh /start.sh
ENTRYPOINT ["bash","/start.sh"]

start.sh

#!/bin/bash

if [ $# -gt 0 ];then
  exec "$@"
else
  tmux new-session -d -x "23" -y "80" -s "skuska" "echo start;sleep 60;echo stop" && \
  tmux set -g status off && tmux attach
fi

Test

$docker build -t local/tmux .
...
$docker run -d local/tmux:latest
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
a875ad0cbde7        169b2a925eb7        "bash /start.sh"    3 seconds ago       Exited (1) 2 seconds ago                       youthful_hopper
$ docker logs a875ad0cbde7
open terminal failed: not a terminal

No, it does not work

Using -i (interactive) and -t (tty)

$ docker run --rm -it local/tmux:latest
start
stop
[exited]

yes it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment