docker - 使用 docker 在 gitea 上 ssh
问题描述
我刚刚在 Linux mint 19 上使用 docker 安装了 gitea,我使用 /data 和旧的 gitea 安装,所以我有一个填充数据库和存储库。当我访问网络时,它似乎工作正常。
问题是使用 SSH:
➜ /tmp sudo git clone git@gitealocal:felipe/test.git
Cloning into 'test'...
ssh: connect to host gitealocal port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
➜ /tmp ssh -vT gitealocal
OpenSSH_7.6p1 Ubuntu-4ubuntu0.1, OpenSSL 1.0.2n 7 Dec 2017
debug1: Reading configuration data /home/felipe/.ssh/config
debug1: /home/felipe/.ssh/config line 16: Applying options for gitealocal
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to gitealocal [127.0.1.1] port 10022.
debug1: Connection established.
debug1: identity file /home/felipe/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.1
ssh_exchange_identification: Connection closed by remote host
我检查了目录和文件的权限,/var/lib/gitea/ssh
但它似乎是正确的。drwx------
和-rw-------
解决方案
22
启动docker容器时需要暴露ssh端口,试试:
docker run --expose 22 ...
EXPOSE 22
或者根据官方文档更好地添加到 Dockerfile 和 SSH 登录修复:
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
推荐阅读
- kubernetes - 如何将 k8 秘密放入 docker cmd 参数中?
- grails - What is the behavor of pessimistic locking when accessing a belongsTo or other relationship?
- swift - 无法将变量设置为文本字段的值
- javascript - 在TextGeometry的three.js中加载字体时出现CORS策略错误
- javascript - 有没有 ”
" jQuery 中的函数?
- angular - 创建与 Angular 路由器路径匹配的唯一快速路由
- c++ - 从初始化列表创建一个 simd::float2
- android - 将firebase消息添加到flutter android项目时出现依赖错误
- node.js - 如何在 Express 中修复“EventSource 的响应具有不是“text/event-stream”的 MIME 类型(“text/html”)?
- java - Java 编译器:两个具有相同名称和不同签名的方法如何匹配一个方法调用?