[英]Debugging rails app running docker with vagrant
I'm trying to figure out the best development workflow with vagrant and docker running a rails app. 我正试图找出运行rails应用程序的vagrant和docker的最佳开发工作流程。 In my dockerfile I have this:
在我的dockerfile中我有这个:
FROM quirky/rails:latest
RUN mkdir /opt/app
WORKDIR /opt/app
# Install gems
ADD ./Gemfile /opt/app/Gemfile
ADD ./Gemfile.lock /opt/app/Gemfile.lock
RUN bundle install
# Instal npm packages
ADD ./package.json /opt/app/package.json
RUN npm install
# Expose directories and ports
VOLUME /opt/app
EXPOSE 3000
# Run the web server
WORKDIR /opt/app
CMD rm -f /opt/app/tmp/pids/server.pid && bundle exec rails s
My Vagrantfile looks like this: 我的Vagrantfile看起来像这样:
config.vm.define "app" do |app|
app.vm.provider "docker" do |d|
d.build_dir = "."
d.link "db:db"
d.link "redis:redis"
d.link "solr:solr"
d.volumes = ["/app:/opt/app"]
d.ports = ["3000:3000"]
d.vagrant_vagrantfile = "./docker/Vagrantfile"
d.remains_running = true
end
end
config.vm.define "db" do |db|
db.vm.provider "docker" do |d|
d.image = "paintedfox/postgresql"
d.name = "db"
d.env = {USER: "vagrant", PASS: "password"}
d.vagrant_vagrantfile = "./docker/Vagrantfile"
end
end
config.vm.define "redis" do |redis|
redis.vm.provider "docker" do |d|
d.image = "dockerfile/redis"
d.name = "redis"
d.ports = ["6379:6379"]
d.vagrant_vagrantfile = "./docker/Vagrantfile"
end
end
config.vm.define "solr" do |solr|
solr.vm.provider "docker" do |d|
d.image = "quirky/solr"
d.name = "solr"
d.ports = ["8080:8080"]
d.vagrant_vagrantfile = "./docker/Vagrantfile"
end
end
Typically if I want to debug something I just stick a debugger
statement in the code and I'm running it as a local process and it just hits the breakpoint and brings up pry or whatever the debugger console is. 通常,如果我想调试一些东西,我只是在代码中粘贴一个
debugger
语句,我将它作为本地进程运行,它只是命中断点并调出pry或调试器控制台。 How does this work inside of a container inside vagrant? 这是如何在流浪汉内的容器内工作的?
This is how I start my dev environment: 这就是我开始我的开发环境的方式:
vagrant up app --provider=docker
It launches it in the background. 它在后台启动它。 There doesn't appear to be a way to launch it and attach to it.
似乎没有办法启动它并附加到它。 Am I missing a command or a flag I can pass in to vagrant?
我错过了一个可以传递给流浪汉的命令或旗帜吗?
You are looking for docker exec
or nsenter
[ 1 ]. 您正在寻找
nsenter
docker exec
或nsenter
[ 1 ]。 With one of these tools you can log into the container without SSH and check your logs. 使用其中一个工具,您可以在没有SSH的情况下登录容器并检查日志。
If you want to debug vagrant creating and running the docker-container you can append the --debug
flag like so: 如果你想调试vagrant创建并运行docker-container,你可以像这样附加
--debug
标志:
vagrant up app --provider=docker --debug
But this won't give you any debug-info from your Vagrantfile directly. 但这不会直接从您的Vagrantfile中提供任何调试信息。 If you still want to get debug-messages out of your vagrantfile I recommend you to read about vagrants UI class.
如果您仍想从vagrantfile中获取调试消息,我建议您阅读有关vagrants UI类的信息。
PS: Maybe you simply want puts
statements like so: puts "I'm here!"
PS:也许你只是想要这样的
puts
语句: puts "I'm here!"
? ?
PPS: If you want to stick with vagrant and SSH the has_ssh
value and a SSH-Server in the container is the way to go. PPS:如果你想坚持使用vagrant和SSH,可以使用容器中的
has_ssh
值和SSH-Server。
Have you tried the has_ssh option for the Vagrand Docker provider? 您是否尝试过Vagrand Docker提供程序的has_ssh选项? It states that:
它指出:
If true, then Vagrant will support SSH with the container.
如果为true,则Vagrant将支持使用容器的SSH。 This allows vagrant ssh to work, provisioners, etc. This defaults to false
这允许vagrant ssh工作,配置器等。默认为false
As an aside, I haven't tried this myself. 顺便说一句,我自己没试过。 I'm using Docker with a CoreOS image and running docker containers manually (with provisioning).
我正在使用Docker和CoreOS映像并手动运行docker容器(使用配置)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.