2014-08-30 61 views
3

我的目標是從Docker容器運行瓶頸webserver。在Windows機器上工作時,需要使用Vagrant來創建虛擬機。運行遊民了--provider =泊塢窗導致以下投訴:調試vagrant + docker + flask的最佳實踐

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 

這是我Dockerfile

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 

這是Vagrantfile

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和運行。 Py獨立工作沒有麻煩,我懷疑我在Dockerfile中犯了一個錯誤。我的問題是雙重的:

  1. Dockerfile或 Vagrantfile是否有明顯的錯誤?
  2. 有沒有辦法讓流浪者/碼頭工生產更多 特定的錯誤信息?
+0

'python run.py'啓動一個守護進程還是這個程序在前臺運行?如果它運行一個守護進程,那麼docker容器將停止。 – Thomasleveil 2014-08-31 19:49:17

回答

1

我想我正在尋找的答案是使用命令vagrant docker-logs。我打破了Dockerfile,因爲我沒有認識到好的行爲,因爲如果應用程序按照它應該運行,沒有真正發生。 docker-logs確認燒瓶應用程序正在偵聽請求。

0

Dockerfile或Vagrantfile是否有明顯的錯誤?

你Dockerfile和Vagrantfiles看起來不錯,但我認爲你需要修改run.py的權限爲可執行:

... 
#copy the working directory to the container 
ADD ./
RUN chmod +x run.py 

CMD python run.py 

運作的?

有沒有辦法讓vagrant/docker產生更具體的錯誤信息?

試着看看vagrant debugging page。我使用的另一種方法是登錄容器並嘗試手動運行腳本。

# 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 

另外,如果你想在本地查看您的應用程序,你需要添加port forwarding您Vagrantfile。