1

作为Docker run cannot find executable "uwsgi"的后续问题 :

我已成功执行docker build,并且docker runDockerfile 为:

FROM python:2-onbuild

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# RUN pip install -r ./requirements.txt
RUN pip install uwsgi

EXPOSE 8000

CMD ["/usr/local/bin/uwsgi", "--http", " :8000" , "--wsgi-file", "falconapp.wsgi"]

我知道它正在运行,因为我在终端上看到了这个输出:

dacao@Das-MacBook-Pro:~/Documents/bitbucket_2/heatmap_api$ docker run -p 8000:8000 image_heatmap
*** Starting uWSGI 2.0.17 (64bit) on [Tue Mar  6 01:57:52 2018] ***
compiled with version: 4.9.2 on 02 March 2018 19:46:35
os: Linux-4.9.60-linuxkit-aufs #1 SMP Mon Nov 6 16:00:12 UTC 2017
nodename: cc47a3a586e7
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /app
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** WARNING: you are running uWSGI without its master process manager ***
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on  :8000 fd 4
spawned uWSGI http 1 (pid: 7)
uwsgi socket 0 bound to TCP address 127.0.0.1:39275 (port auto-assigned) fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
Python version: 2.7.14 (default, Feb 17 2018, 09:47:19)  [GCC 4.9.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1e966f0
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x1e966f0 pid: 1 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 1, cores: 1)

而且我确定 Docker 映像正在运行:

dacao@Das-MacBook-Pro:~/Documents/bitbucket_2/heatmap_api$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
cc47a3a586e7        image_heatmap       "/usr/local/bin/uwsg…"   16 minutes ago      Up 17 minutes       0.0.0.0:8000->8000/tcp   laughing_nightingale
dacao@Das-MacBook-Pro:~/Documents/bitbucket_2/heatmap_api$ 

接下来,我想检查我的应用程序是否真的在运行。我在我的 Safari 浏览器上尝试了以下网址:

http://127.0.0.1:8000/healthcheck 
http://localhost:8000/healthcheck 
http://host-ip:8000/healthcheck

但都没有奏效。所有人都给出了“无法打开页面”错误。
如何访问我的应用程序?

对不起,我是菜鸟,对 docker 很陌生

更新:

我试过docker-machine ip了,它给出了Error: No machine name(s) specified and no "default" machine exists. 我不明白,因为我确定图像正在运行 - 我检查docker ps并查看了 CONTAINER ID IMAGE 等。

我也试过docker-machine ls了,它给出了空列表:NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS

我应该在我之前docker-machine startdocker-machine create default之前创建一个 docker-machineDocker run ... 吗?

4

2 回答 2

0

您在容器中的 HTTP 服务器在端口 8000 上运行,因此如果您想在主机上看到它,您必须使用以下模式发布端口:

docker run -p <host-port>:<container-port> smaller_runner

因此,如果您想访问主机上 8000 端口上的容器,则必须运行此命令:

docker run -p 8000:8000 smaller_runner

然后您可以检查以下网址之一:

http://127.0.0.1:8000/healthcheck
http://localhost:8000/healthcheck
http://host-ip:8000/healthcheck

如果您想在后台运行容器,请使用-dit它:

docker run -dit --name test -p 8000:8000 smaller_runner

于 2018-03-03T12:48:26.713 回答
0

查看启动日志后,看起来问题出在uWSGI配置上。

似乎服务器只监听127.0.0.1docker 容器内的本地主机。您是否尝试在uWSGIHOST配置中设置为?并且不要忘记将端口绑定到主机。0.0.0.0

于 2018-07-23T04:47:36.350 回答