我有一些在P2实例上运行的Docker容器。 过去我在P2实例中运行tmux并在其中运行Docker容器。 之后,我使用
docker exec -it
为了进入正在运行的Docker容器,我想避免上述方法,并希望能够在现有容器中运行tmux。
tmux new -s <some name>
没有任何作用。
我猜您想要通过tmux
远程连接到运行的docker容器。为了实现这一点,您需要在容器内运行一个ssh服务器,并使用ssh
附加到tmux
会话。例如:
Create the container image with ssh
and tmux
installed. The Dockerfile
might look like this:
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:
docker run -it -d -p 8654:22 <image name>
Attach to the tmux
session:
ssh user@<hostname> -p 8654 -t "tmux a -t mysesh"
注意: tmux
会话是针对用户的,因此请确保用户存在于容器中,并且在容器内作为该用户启动tmux
会话。
tmux
服务器套接字,而不是运行一个ssh
实例。 - chepner在 Docker 镜像中可能没有安装 tmux,您可以在连接到 Docker 容器后安装它。
sudo apt install tmux
然后你应该能够执行
tmux new -s <some name>
在 P3 机器上尝试过,运行良好。 参考:https://linuxize.com/post/getting-started-with-tmux/
docker exec
进入正在运行的容器。也许您想解释一下为什么需要 tmux,以及您的最终目标是什么。 - Sathyajith Bhattmux
服务器,然后使用本地的tmux
客户端连接到会话? - chepner