2017-04-25 59 views
2

我在Python Flask webapp上使用Docker,但在嘗試運行時收到錯誤。正在運行Docker鏡像給出:無法從app.py加載配置

$ sudo docker run -t imgcomparer6 
unable to load configuration from app.py 

的Python

在我app.py文件,在webapp我的app.run()唯一實例是 '__main__':功能(看到here

if __name__ == '__main__': 
    app.run(host="127.0.0.1", port=int("8000"), debug=True) 

Dockerfile

FROM ubuntu:latest 

#Update OS 
RUN sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list 
RUN apt-get update 
RUN apt-get -y upgrade 

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


RUN mkdir /webapp/ 

# Add requirements.txt 
ADD requirements.txt /webapp/ 
ADD requirements.txt . 

# Install uwsgi Python web server 
RUN pip install uwsgi 

# Install app requirements 
RUN pip install -r requirements.txt 


# Create app directory 
ADD . /webapp/ 

# Set the default directory for our environment 
ENV HOME /webapp/ 
WORKDIR /webapp/ 

# Expose port 8000 for uwsgi 
EXPOSE 8000 


ENTRYPOINT ["uwsgi", "--http", "127.0.0.1:8000", "--module", "app:app", "--processes", "1", "--threads", "8"] 
#ENTRYPOINT ["python"] 
CMD ["app.py"] 

目錄結構

app.py 
image_data.db 
README.txt 
requirements.txt 
Dockerfile 
templates 
- index.html 
static/ 
- image.js 
- main.css 
img/ 
    - camera.png 
images/ 
    - empty 

編輯:

泊塢圖像

[email protected]:~/Desktop/brian_castro_programming_test$ sudo docker images 
REPOSITORY   TAG     IMAGE ID   CREATED    SIZE 
imgcomparer6  latest    d2af1b18ec87  59 minutes ago  430 MB 
imgcomparer5  latest    305fa5062b41  About an hour ago 430 MB 
<none>    <none>    e982e54b011a  About an hour ago 430 MB 
imgcomparer2  latest    c7e3ad57be55  About an hour ago 430 MB 
imgcomparer   latest    a1402ec1efb1  About an hour ago 430 MB 
<none>    <none>    8f5126108354  14 hours ago  425 MB 
flask-sample-one latest    9bdc51fa4d7c  23 hours ago  453 MB 
ubuntu    latest    6a2f32de169d  12 days ago   117 MB 

圖像日誌(給出錯誤)

sudo docker logs imgcomparer6 
Error: No such container: imgcomparer6 

試圖運行此,所建議的BEL ow:

'$ sudo docker run -t imgcomparer6; sudo的日誌泊塢窗$(泊塢窗PS -lq)」

unable to load configuration from app.py 
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.27/containers/json?limit=1: dial unix /var/run/docker.sock: connect: permission denied 
"docker logs" requires exactly 1 argument(s). 
See 'docker logs --help'. 

Usage: docker logs [OPTIONS] CONTAINER 

Fetch the logs of a container 

PS -a

CONTAINER ID  IMAGE    COMMAND     CREATED    STATUS      PORTS    NAMES 
e80bfd0a3a11  imgcomparer6  "uwsgi --http 127...." 54 minutes ago  Exited (1) 54 minutes ago      musing_fermat 
29c188ede9ba  imgcomparer6  "uwsgi --http 127...." 54 minutes ago  Exited (1) 54 minutes ago      kind_jepsen 
a58945d9cd86  imgcomparer6  "uwsgi --http 127...." 55 minutes ago  Exited (1) 55 minutes ago      musing_wright 
ca70b624df5e  imgcomparer6  "uwsgi --http 127...." 55 minutes ago  Exited (1) 55 minutes ago      brave_hugle 
964a1366b105  imgcomparer6  "uwsgi --http 127...." 55 minutes ago  Exited (1) 55 minutes ago      clever_almeida 
155c296a3dce  imgcomparer6  "uwsgi --http 127...." 2 hours ago   Exited (1) 2 hours ago       jovial_heisenberg 
0a6a3bb55b55  imgcomparer5  "uwsgi --http 127...." 2 hours ago   Exited (1) 2 hours ago       sharp_mclean 
76d4f40c4b82  e982e54b011a  "uwsgi --http 127...." 2 hours ago   Exited (1) 2 hours ago       kind_hodgkin 
918954bf416a  d73c44a6c215  "/bin/sh -c 'mkdir..." 2 hours ago   Exited (1) 2 hours ago       amazing_bassi 
205276ba1ab2  d73c44a6c215  "/bin/sh -c 'mkdir..." 2 hours ago   Exited (1) 2 hours ago       distracted_joliot 
86a180f071c6  d73c44a6c215  "/bin/sh -c '#(nop..." 2 hours ago   Created           goofy_torvalds 
fc1ec345c236  imgcomparer2  "uwsgi --http 127...." 2 hours ago   Created           wizardly_boyd 
b051d4cdf0c6  imgcomparer   "uwsgi --http 127...." 2 hours ago   Created           jovial_mclean 
ed78e965755c  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           elated_shirley 
a65978d30c8f  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           vigilant_wright 
760ac5a0281b  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           xenodochial_heyrovsky 
9d7d8bcb2226  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           sleepy_noyce 
36012d4c6115  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           adoring_hypatia 
deacab89f416  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           objective_franklin 
43e894f8fb9c  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           sleepy_hodgkin 
2d190d0fc6e5  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           modest_hoover 
b1640a039c31  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           affectionate_galileo 
baf94cf2dc6e  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           affectionate_elion 
2b54996907b6  d73c44a6c215  "/bin/sh -c '#(nop..." 3 hours ago   Created           elastic_wiles 
663d4e096938  8f5126108354  "/bin/sh -c 'pip i..." 15 hours ago  Exited (1) 15 hours ago       admiring_agnesi 
+0

後'碼頭工人日誌your_container'也'泊塢窗事件'當您啓動呢?這是不是你的問題,但你hsould組跑步,看到https://docs.docker.com/engine/userguide/eng-image/dockerfile_best實踐/ – user2915097

+0

你需要運行容器做'泊塢窗ps'。 –

+0

post'sudo docker run -t imgcomparer6;泊塢窗登錄$(泊塢窗PS -lq)' – user2915097

回答

0

這裏是app.py兩個快速修復和Dockerfile,它應該運行。

更改任何127.0.0.1引用0.0.0.0。 Docker綁定0.0.0.0上的端口。

app.run(host="0.0.0.0", port=int("8000"), debug=True) 

對於Dockerfile你可以使用CMD和/或ENTRYPOINT當容器啓動時,但在這種情況下,你不需要都運行命令。這將工作:

CMD exec uwsgi --http 0.0.0.0:8000 --module app:app --processes 1 --threads 8 

然後:

docker build . 
docker run -p 8000:8000 <image> 
0

你的問題是你如何調用uwsgi。你傳遞的方式app.py告訴uwsgi它是一個配置文件,而不是一個python可調用的。

我更喜歡使用ini文件來配置uwsgi,因爲它比向Dockerfile添加一堆命令行選項更清潔。如果遇到問題,請參閱相關文檔以瞭解如何部署flask和uwsgi。

Uwsgi: Quickstart Flask

下面是一個示例uwsgi.ini和Dockerfile配置。它基於的例子在uwsgi的文檔,使用wsgi-filecallable參數來啓動燒瓶WSGI功能。無論你是否在docker中運行,這應該都是一樣的。

(這意味着有應該是在app.py的if __name__塊沒有用)

uwsgi.ini:

[uwsgi] 
socket = 0.0.0.0:8000 
chdir = /webapp/ 
wsgi-file = app.py 
callable = app 
... 

Dockerfile:使用

... 
# no ENTRYPOINT, use only CMD 
CMD ["uwsgi", "/webapp/uwsgi.ini"] 

既避免入口點和CMD,直到你完全理解how they interact。如果有疑問,只需使用CMD。

相關問題