Docker中的debuggingrails应用程序使用Intellij / Rubymine
我开始使用Docker开发rails开发。 目前,我遵循一些教程来设置开发环境。 一切正常。 (用于构build,运行)。 但是现在,我想为Rubymine设置Ruby Remote SDK,所以我在Docker容器上安装了SSH(ruby容器;我安装了SSH,因为它需要设置REMOTE SDK)。
这里是Dockerfile
FROM ruby:2.2.0 # Install package RUN apt-get update -qq && apt-get install -y \ build-essential \ libpq-dev \ nodejs \ openssh-server # Setting sshd RUN mkdir /var/run/sshd RUN echo 'root:root' | chpasswd RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /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"] 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: db: image: postgres web: build: . command: bundle exec rails s -p 3000 -b '0.0.0.0' volumes: - .:/myapp ports: - "3000:3000" - "22" depends_on: - db
(对于ssh – > in this link https://docs.docker.com/engine/examples/running_ssh_service/ )
然后我连接SSH到容器。 这是我的步骤:
-
获取ssh的端口:
docker端口demorailsdocker_web_1
#这是结果
22 / tcp – > 0.0.0.0:32768
3000 / tcp – > 0.0.0.0:3000
-
连接SSH到容器
ssh root @ localhost -p 32768
#结果ssh_exchange_identification:由远程主机closures的连接
我发现这个问题与Dockerfile中的设置有关。
因为当我在docker文件中删除这些行时:
RUN mkdir /myapp WORKDIR /myapp ADD Gemfile /myapp/Gemfile ADD Gemfile.lock /myapp/Gemfile.lock RUN bundle install ADD . /myapp
在docker-compose.yml中删除这些行
volumes: - .:/myapp
然后我可以连接到SSH。
我认为这个问题是关于设置工作目录。
通过在docker-compose.yml中删除这一行,我可以很好地将SSH连接到容器
command: bundle exec rails s -p 3000 -b '0.0.0.0'
所以我认为这个问题是关于rails的。 但是我不知道如何解决这个问题。
我设法使用RubyMine远程debugging运行在docker中的rails,而不使用SSH。
我的环境中的软件版本如下
- RubyMine 2017.2.4(Build#RM-172.4155.44,构build于2017年9月26日)
- Ruby里面的docker(ruby2.4.2p198(2017-09-14修订59899)[x86_64-linux])
- RubyMine使用的Ruby SDK和Gem(ruby-2.4.2-p198)
注意:对于Ruby SDK,我只是使用本地的Ruby解释器/ usr / bin / ruby,而不是远程的解释器。
以下是演示的详细步骤
1.启动docker
docker run --name rails-demo -p 1234:1234 -p 3080:3000 -it ruby bash
2.docker内的步骤
确保你的Gemfile中有下列gem,如果gem是在那里,最好还是注释一下gem pry-byebug,以避免可能的干扰。
# gem 'pry-byebug' gem 'debase', '0.2.2.beta10' gem 'ruby-debug-ide'
根据需要更新应用程序的依赖关系
bundle install
启动你的rails服务器
/home/hello_rails# rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails s
3.从RubyMine远程debugging
现在启动RubyMine,运行 – >debugging… – >编辑configuration…
点击加号“+”添加新configuration,然后selectRuby远程debugging。
填写如上所示的表单,然后单击debuggingbutton。 现在你将在Docker中看到Rails服务器开始了:
/home/hello_rails# rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails s Fast Debugger (ruby-debug-ide 0.6.0, debase 0.2.2.beta10, file filtering is supported) listens on 0.0.0.0:1234 => Booting Puma => Rails 5.1.4 application starting in development => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.10.0 (ruby 2.4.2-p198), codename: Russell's Teapot * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://0.0.0.0:3000 Use Ctrl-C to stop
现在,您可以在RubyMine中设置断点,并开始远程debugging它:-)
转到浏览器的URL: http:// localhost:3080 / say / hi (注意端口3080从3000映射,请参阅启动docker的命令)
断点如下所示,可以检查variables等
值得一提的是,确保networking服务器美洲狮开始在单一模式。 对于我来说,集群模式不适用于远程debugging,在那里你会遇到像“终止超时工人”这样的错误。 为了发展,单一模式应该足够好。
最好我可以告诉你debuggingRuby / Rails的容器,而不需要SSH进入专门用于远程debugging的ruby-debug-ide
gem:
创业板: https : //github.com/ruby-debug/ruby-debug-ide
如何: http : //bzzt.io/posts/running-the-rails-debugger-in-a-docker-container-using-rubymine
你也可以使用这个Dockerfile来正确设置SSH,这将允许你远程连接到你的Web容器:
GitHub: https : //github.com/zchee/docker-rubymine
Dockerfile: https : //github.com/zchee/docker-rubymine/blob/master/Dockerfile
- 在Mesosphere中的“args”是否与docker run命令中的环境variables相当?
- dockers / IBM bluemix中的openconnect(错误:TUNSETIFF失败:设备不适当的ioctl)
- 使用docker部署Java战争
- 在Caliconetworking的Docker容器中使用ping检查容器连接
- 如何在docker中访问guest IP
- 何时使用Docker-Compose以及何时使用Docker-Swarm
- Jenkins没有在Windows 7上识别“docker”命令
- 在Docker Centos上安装后,Mongo不运行:无法连接到127.0.0.1:27017
- 检索泊坞窗图像ID