如何在Docker容器中配置Debian SSHD进行远程调试? [英] How to configure Debian SSHD for remote debugging in a Docker container?
问题描述
我正在尝试对Docker Debian容器进行远程调试,以便在Windows笔记本电脑上调试Ruby应用程序。
I'm trying to setup remote debugging to a Docker Debian container, to debug a Ruby application on my Windows laptop.
This is the post that lead me in this direction: 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发行版不完全兼容。
I have the Ruby app and SSHD running in the container, though the recipe I found for configuring SSHD isn't fully compatible with the Linux distro that the Ruby image is based on.
我在此Docker文档中基于我的SSHD配置页面: https://docs.docker.com/engine/examples/running_ssh_service/
I based my SSHD configuration on this Docker documentation page: https://docs.docker.com/engine/examples/running_ssh_service/
我的图像基于Docker Hub的ruby 2.2版本,它使用Debian 8,而不是上述SSHD示例中使用的Ubuntu 16.04。
My image is based on the ruby:2.2 image from Docker Hub, which uses Debian 8 as opposed to Ubuntu 16.04 used in the SSHD example above.
我可以得到一个SSH提示符,但是我无法使用dockerfile中设置的root用户的screencast密码登录。
I can get to a SSH prompt but I can't login with the screencast password for root that's set in the dockerfile.
我打开无论是正确启用root登录还是添加具有正确权限的新用户以进行远程调试,无论解决方案如何。我只是好奇Debian背景下最直接的路径。如果它正在创建一个新的用户,他们需要什么权限?
I'm open to whatever solution works, either properly enabling root login or adding a new user with the correct permissions to allow for remote debugging. I'm just curious which path would be most straight forward in the Debian context. And if it's creating a new user, what permissions do they need?
另外,要清楚,我把它当作一个试运行,显然肯定会剥离在开发之外的任何上下文部署应用程序时,都可以使用SSHD功能。
Also, to be clear I'm treating this as a trial run and will obviously make sure to strip out the SSHD functionality in some way when I go to deploy the app for any context outside of development.
提前感谢您的帮助。
这是我目前的dockerfile
This is my current 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
and this is my 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看起来像这样
The docker-dev-start.sh looks like this
#!/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'
推荐答案
不同的发行版可能会略有不同的SSH配置,因此替换特定字符串可能无法正常工作。
Different distro's can have slightly different SSH configs so replacing specific strings might not work.
覆盖任何类型的 PermitRootLogin
string use:
To cover any type of PermitRootLogin
string use:
RUN sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
这篇关于如何在Docker容器中配置Debian SSHD进行远程调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!