SSH 直接进入 docker 容器 [英] SSH directly into a docker container

查看:27
本文介绍了SSH 直接进入 docker 容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 docker conatiners,现在我想使用 ssh 访问其中一个.那是有效的,我通过 ssh 连接到 docker 容器.

i've got some docker conatiners and now I want to access into one with ssh. Thats working I got a connection via ssh to the docker container.

但是现在我有一个问题,我不知道我可以通过哪个用户访问这个容器?

But now I have the problem I don't know with which user I can access into this container?

我已经对主机上的两个用户(网络和根)进行了尝试.但它们不起作用.要知道什么?

I've tried it with both users I have on the host machine (web & root). But they don't work. What to do know?

推荐答案

您可以直接放入正在运行的容器中:

You can drop directly into a running container with:

$ docker exec -it myContainer /bin/bash

您可以在未运行的容器上获取​​ shell:

You can get a shell on a container that is not running with:

$ docker run -it myContainer /bin/bash

这是在容器上获取​​ shell 的首选方法.运行 SSH 服务器被认为不是一个好的做法,尽管有一些用例,但应尽可能避免.

This is the preferred method of getting a shell on a container. Running an SSH server is considered not a good practice and, although there are some use cases out there, should be avoided when possible.

这篇关于SSH 直接进入 docker 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆