tmux on Docker - blitterated/docker-dev-env GitHub Wiki
Is it better to do
docker run -it --rm foo /bin/bash
tmuxor
docker run -it --rm foo /usr/bin/tmuxDoesn't seem to matter. Just running tmux on its own picks up on the shell set for the user in /etc/passwd.
Would it be better to just use CMD to run tmux?
Create an image with tmux installed.
cat <<"EOF" > Dockerfile
FROM ubuntu
RUN apt update && apt --yes upgrade && \
apt install --yes tmux
EOFdocker build -t tmuxing .Create a named container running tmux.
docker run -it --name tmux_shell tmuxing /usr/bin/tmuxCheck to see if tmux is running and which shell is running.
ps a PID TTY STAT TIME COMMAND
1 pts/0 Ss+ 0:00 /usr/bin/tmux
10 pts/1 Ss 0:00 -bash
20 pts/1 R+ 0:00 ps a
See what other shells are available on the image.
cat /etc/shells# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/usr/bin/tmux
Setup the root user to use dash shell instead.
usermod --shell /bin/dash rootBail out of the container so we can restart it.
exitRestart and attach to the container.
docker start --attach -i tmux_shellCheck again to see if tmux is running and which shell is running.
ps a PID TTY STAT TIME COMMAND
1 pts/0 Ss+ 0:00 /usr/bin/tmux
9 pts/1 Ss 0:00 -dash
14 pts/1 R+ 0:00 ps a
And we're up and running with dash instead. This shows that tmux uses the user's default shell.
Exit out, and then delete the image.
exitdocker rm tmux_shellOverwrite the Dockerfile with a new one that uses CMD.
cat <<"EOF" > Dockerfile
FROM ubuntu
RUN apt update && apt --yes upgrade && \
apt install --yes tmux
CMD ["tmux"]
EOFBuild the image.
docker build -t tmuxd .Run a container in daemon mode.
docker run -d --name tmuxd_test tmuxdCheck on it.
docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
71a754b70a2c tmuxd "tmux" 35 seconds ago Exited (1) 34 seconds ago tmuxd_test
That quit pretty much immediately.
Let's try by explicitly starting a tmux session.
First, delete the old image and container.
docker rm tmuxd_test
docker rmi tmuxdUpdate the Dockerfile.
cat <<"EOF" > Dockerfile
FROM ubuntu
RUN apt update && apt --yes upgrade && \
apt install --yes tmux
ENTRYPOINT ["tmux"]
CMD ["new-session", "-s", "tmux-test", "/bin/bash"]
EOFBuild the image.
docker build -t tmuxd .Run a container in daemon mode.
docker run -d --name tmuxd_test tmuxdCheck on it.
docker ps -aThis also bailed immediately.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd728aa7dbc5 tmuxd "tmux new-session -s…" 5 seconds ago Exited (1) 4 seconds ago tmuxd_test
Tried to start and attach unsuccessfully in a couple of ways.
docker start -a tmuxd_testdocker start -i tmuxd_testdocker start -ia tmuxd_testThey all exited with the same message.
open terminal failed: not a terminal
Running the same command interactively works fine.
docker run -it --rm --entrypoint tmux tmuxd new-session -s tmux-test /bin/bashNot sure how to keep the session up and running while in daemon mode. Overall this was a good set of experiments with Docker and tmux.