【发布时间】:2017-10-31 19:25:29
【问题描述】:
我正在为需要 ssh 到 localhost(即 ssh user@localhost)的应用程序构建 Docker 映像
我正在使用 Ubuntu 桌面机器,并从一个基本的 ubuntu:16.04 容器开始。 以下是我的 Dockerfile 的内容:
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y \
openjdk-8-jdk \
ssh && \
groupadd -r custom_group && useradd -r -g custom_group -m user1
USER user1
RUN ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N "" && \
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
然后我使用命令构建这个容器:
docker build -t test-container .
并使用以下命令运行它:
docker run -it test-container
容器打开并显示以下提示,并且正确生成密钥以启用 ssh 进入 localhost:
user1@0531c0f71e0a:/$
user1@0531c0f71e0a:/$ cd ~/.ssh/
user1@0531c0f71e0a:~/.ssh$ ls
authorized_keys id_rsa id_rsa.pub
然后 ssh 进入 localhost 并出现错误:
user1@0531c0f71e0a:~$ ssh user1@localhost
ssh: connect to host localhost port 22: Cannot assign requested address
我做错了什么或需要配置任何其他网络设置吗?我只想通过 ssh 进入正在运行的容器中的 localhost。
【问题讨论】:
-
我猜你选择了错误的包名,即。 ssh 而不是 openssh-server
-
您使用 IP v6 吗?尝试
ssh -4 -v添加详细并强制 IP v4 -
嗨@rups 我将'ssh'更改为'openssh-server',仍然受到同样错误的困扰:\
-
嗨@user2915097,我在命令中添加了标志并得到:
user1@4117512c2196:/$ ssh -4 -v user1@localhost OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to localhost [127.0.0.1] port 22. debug1: connect to address 127.0.0.1 port 22: Connection refused debug1: Connecting to localhost [127.0.0.1] port 22. debug1: connect to address 127.0.0.1 port 22: Connection refused ssh: connect to host localhost port 22: Connection refused -
你在哪里启动了 ssh 服务?
标签: linux docker ssh localhost containers