【问题标题】:How to configure Debian SSHD for remote debugging in a Docker container?如何在 Docker 容器中配置 Debian SSHD 以进行远程调试?
【发布时间】:2017-07-27 23:29:15
【问题描述】:

我正在尝试对 Docker Debian 容器进行远程调试,以便在我的 Windows 笔记本电脑上调试 Ruby 应用程序。

这是引导我朝这个方向发展的帖子: https://intellij-support.jetbrains.com/hc/en-us/community/posts/207649545-Use-RubyMine-and-Docker-for-development-run-and-debug-before-deployment-for-testing-

我在容器中运行了 Ruby 应用程序和 SSHD,但我找到的配置 SSHD 的方法与 Ruby 映像所基于的 Linux 发行版不完全兼容。

我的 SSHD 配置基于此 Docker 文档页面:https://docs.docker.com/engine/examples/running_ssh_service/

我的映像基于 Docker Hub 的 ruby​​:2.2 映像,它使用 Debian 8 而不是上面 SSHD 示例中使用的 Ubuntu 16.04。

我可以进入 SSH 提示,但我无法使用 dockerfile 中设置的 root 的截屏密码登录。

我愿意接受任何可行的解决方案,无论是正确启用 root 登录还是添加具有正确权限的新用户以允许远程调试。我只是好奇在 Debian 环境中哪条路径最直接。如果是创建一个新用户,他们需要什么权限?

另外,需要明确的是,我将此视为试运行,并且当我为开发之外的任何上下文部署应用程序时,显然会确保以某种方式剥离 SSHD 功能。

提前感谢您的帮助。

这是我当前的 dockerfile

FROM ruby:2.2
RUN apt-get update && apt-get install -y \
    build-essential \
    libpq-dev \
    nodejs \
    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

RUN mkdir /MyApp
WORKDIR /MyApp
ADD Gemfile /MyApp/Gemfile
ADD Gemfile.lock /MyApp/Gemfile.lock
RUN bundle install
ADD . /MyApp

这是我的 docker-compose.yml

version: '2'
services:
  web:
    build: .
    command: /CivilService/docker-dev-start.sh
    volumes:
      - .:/CivilService
    ports:
      - "3000:3000"
      - "3022:22"

docker-dev-start.sh 看起来像这样

#!/bin/bash

# start the SSH server for connecting the debugger in development
/usr/sbin/sshd -D &
bundle exec rails s -p 3000 -b '0.0.0.0'

【问题讨论】:

  • 您的 Dockerfile 缺少 CMD 或 ENTRYPOINT
  • @user2915097 docker-compose.yml 在你运行docker-compose up时应用命令
  • 将您的 sed 更改为 RUN sed -i 's/PermitRootLogin .*/PermitRootLogin yes/'
  • @Matt 谢谢!做到了!

标签: docker debian sshd


【解决方案1】:

不同发行版的 SSH 配置可能略有不同,因此替换特定字符串可能不起作用。

要覆盖任何类型的PermitRootLogin 字符串,请使用:

RUN sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config

【讨论】:

    猜你喜欢
    • 2016-04-06
    • 2018-09-20
    • 2019-11-13
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 2019-05-16
    • 2021-03-17
    • 1970-01-01
    相关资源
    最近更新 更多