[英]How to run tmux inside a docker container?
I have some docker container running on a P2 instance.我在 P2 实例上运行了一些 docker 容器。 In the past I run tmux in the P2 instance a run a docker container inside.
过去我在 P2 实例中运行 tmux 并在里面运行一个 docker 容器。 Afterwards I used
后来我用
docker exec -it
to get into the running docker container.进入正在运行的 docker 容器。 I would like to avoid the above and be able to run tmux inside an existing container.
我想避免上述情况并能够在现有容器内运行 tmux。 hitting
打
tmux new -s <some name>
Doesn't do anything.什么都不做
I assume that you want to connect to a docker container running remotely via tmux
.我假设您想通过
tmux
连接到远程运行的 docker 容器。 In order to do this, you will have to run an ssh server within the container and attach to the tmux
session using ssh
.为此,您必须在容器内运行 ssh 服务器并使用
ssh
附加到tmux
会话。 For example:例如:
Create the container image with ssh
and tmux
installed.创建安装了
ssh
和tmux
的容器镜像。 The Dockerfile
might look like this: Dockerfile
可能如下所示:
FROM ubuntu:latest RUN apt-get update && \\ apt install -y tmux && \\ apt install -y openssh-server && \\ service ssh start && \\ tmux new -s mysesh EXPOSE 22/tcp
Run the container, and port forward the ssh port:运行容器,并转发 ssh 端口:
docker run -it -d -p 8654:22 <image name>
Attach to the tmux
session:附加到
tmux
会话:
ssh user@<hostname> -p 8654 -t "tmux a -t mysesh"
Note : tmux
sessions are user specific, so ensure that the user exists in the container, and that the tmux
session is started as the user within the container.注意:
tmux
会话是特定于用户的,因此请确保该用户存在于容器中,并且tmux
会话以容器内的用户身份启动。
tmux might not be available in docker image, you can install it once you're attached to the docker container. tmux 可能在 docker 镜像中不可用,您可以在附加到 docker 容器后安装它。
sudo apt install tmux
Then you should be able to execute然后你应该能够执行
tmux new -s <some name>
Tried this on a P3 machine worked fine.在 P3 机器上试过这个工作正常。 Reference: https://linuxize.com/post/getting-started-with-tmux/
参考: https : //linuxize.com/post/getting-started-with-tmux/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.