Python 调试vagrant&x2B的最佳实践;docker&x2B;瓶子

Python 调试vagrant&x2B的最佳实践;docker&x2B;瓶子,python,flask,vagrant,docker,Python,Flask,Vagrant,Docker,我的目标是从Docker容器运行flask Web服务器。在Windows计算机上工作这需要Vagrant来创建VM。运行vagrant up--provider=docker会导致以下投诉: INFO interface: error: The container started either never left the "stopped" state or very quickly reverted to the "stopped" state. This is usually becau

我的目标是从Docker容器运行flask Web服务器。在Windows计算机上工作这需要Vagrant来创建VM。运行vagrant up--provider=docker会导致以下投诉:

INFO interface: error: The container started either never left the "stopped" state or
very quickly reverted to the "stopped" state. This is usually
because the container didn't execute a command that kept it running,
and usually indicates a misconfiguration.

If you meant for this container to not remain running, please
set the Docker provider configuration "remains_running" to "false":

  config.vm.provider "docker" do |d|
     d.remains_running = false
  end
这是我的文件

FROM mrmrcoleman/python_webapp

EXPOSE 5000

# Install Python 
RUN apt-get install -y python python-dev python-distribute python-pip

# Add and install Python modules
RUN pip install Flask

#copy the working directory to the container
ADD . /

CMD python run.py
这是流浪汉档案

Vagrant.configure("2") do |config|
  config.vm.provider "docker" do |d|
    d.build_dir = "." #searches for a local dockerfile

  end
  config.vm.synced_folder ".", "/vagrant", type: "rsync"
  rsync__chown = false
end
因为Vagrantfile和run.py可以独立工作,所以我怀疑我在Dockerfile中犯了错误。我的问题有两个:

  • Dockerfile或 流浪汉档案
  • 有没有办法让流浪汉/码头工人生产更多 特定的错误消息
  • Dockerfile或Vagrant文件是否有明显的问题

    您的Dockerfile和Vagrant文件看起来不错,但我认为您需要修改run.py的权限才能执行:

    ...
    #copy the working directory to the container
    ADD . /
    RUN chmod +x run.py
    
    CMD python run.py
    
    这样行吗

    有没有办法让vagrant/docker生成更具体的错误消息

    试着看一看这张照片。我使用的另一种方法是登录到容器并尝试手动运行脚本

    # log onto the vm running docker
    vagrant ssh
    
    # start your container in bash, assuming its already built. 
    docker run -it my/container /bin/bash
    
    # now from inside your container try to start your app
    python run.py
    

    另外,如果你想在本地查看你的应用程序,你需要添加到你的Vagrant文件中。

    我想我想要的答案是使用命令

    vagrant docker-logs
    

    我破坏了Dockerfile,因为我没有意识到良好的行为是这样的,因为如果应用程序按它应该的方式运行,就不会发生任何事情。docker日志确认flask应用程序正在侦听请求。

    python是否运行.py启动守护程序,或者此程序是否在前台运行?如果它运行守护进程,那么docker容器将停止。