2016-07-28 103 views
0

我運行了一個在Docker上運行的Flask樣板應用程序,使用docker run -d -p 80:80 p0bailey/docker-flask 並且它可行(192.168.99.100顯示了一個頁面)。接下來,我從github克隆相同的應用程序,並嘗試從主機目錄掛載到容器使用:從主機到遠程的Docker掛載

docker run -d -p 80:80 -v /Users/username/docker-flask/app:/var/www/app p0bailey/docker-flask 

我去URL 92.168.99.100並得到502 Bad Gateway

我在做什麼錯?

主機是一分錢OS 7

$ docker ps -a 
CONTAINER ID  IMAGE     COMMAND     CREATED    STATUS    PORTS    NAMES 
721e7cfac4de  p0bailey/docker-flask "/usr/bin/supervisord" 10 seconds ago  Up 8 seconds  0.0.0.0:80->80/tcp stoic_newton 

這裏的日誌

$ docker logs 721e7cfac4de 
/usr/lib/python2.7/dist-packages/supervisor/options.py:295: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security. 
    'Supervisord is running as root and it is searching ' 
2016-07-28 21:14:32,788 CRIT Supervisor running as root (no user in config file) 
2016-07-28 21:14:32,788 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing 
2016-07-28 21:14:32,808 INFO RPC interface 'supervisor' initialized 
2016-07-28 21:14:32,808 CRIT Server 'unix_http_server' running without any HTTP authentication checking 
2016-07-28 21:14:32,808 INFO supervisord started with pid 1 
2016-07-28 21:14:33,812 INFO spawned: 'nginx' with pid 10 
2016-07-28 21:14:33,813 INFO spawned: 'uwsgi' with pid 11 
2016-07-28 21:14:33,869 INFO exited: uwsgi (exit status 1; not expected) 
2016-07-28 21:14:34,908 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
2016-07-28 21:14:34,909 INFO spawned: 'uwsgi' with pid 16 
2016-07-28 21:14:34,915 INFO exited: uwsgi (exit status 1; not expected) 
2016-07-28 21:14:36,920 INFO spawned: 'uwsgi' with pid 17 
2016-07-28 21:14:36,926 INFO exited: uwsgi (exit status 1; not expected) 
2016-07-28 21:14:39,934 INFO spawned: 'uwsgi' with pid 18 
2016-07-28 21:14:39,942 INFO exited: uwsgi (exit status 1; not expected) 
2016-07-28 21:14:40,943 INFO gave up: uwsgi entered FATAL state, too many start retries too quickly 
+0

什麼是'92.168.99.100'?你確定你的容器正在監聽該系統上的端口80嗎?你確定容器甚至在運行嗎?向我們展示您的診斷步驟以及您所看到的任何錯誤。 – larsks

+0

@larsks我用'docker ps -a'的輸出更新了問題以顯示它的運行 – DevEx

+0

@larsks我也給它添加了日誌 – DevEx

回答

0

發現了這個有上/應用讀寫權限做定位您的主機的文件系統卷的隨機位置。 將SELinux切換爲寬容模式固定問題。

vim /etc/selinux/config 

#look for line SELINUX and set to permissive 
SELINUX=permissive 
+0

儘管我沒有提供Mac OS – DevEx

0

-v /Users/username/docker-flask/app:/var/www/app覆蓋你的容器組成。如果要安裝/var/www/app/Users/username/docker-flask/app

的內容的內容丟失原始容器文件使用

docker run -d -p 80:80 -v /var/www/app p0bailey/docker-flask 

然後使用

docker inspect -f "{{json .Mounts}}" development-phase \ 
| jq '.[] | select(.Destination | contains("/var/www/app"))' 
+0

但我確實想掛載'/ Users/username/docker-flask/app',因爲計劃是稍後進行更改和部署。 – DevEx

+0

你可以使用'docker cp'或者以前在'/ Users/username/docker-flask/app'中複製'/ var/www/app'(在容器中)的內容(參見https://github.com/p0bailey/docker-flask/tree/master/app) –