【发布时间】:2018-02-12 11:01:39
【问题描述】:
我正在尝试在 docker 容器中运行带有 flask、uwsgi 和 nginx 的 Docker 容器。
我的 Dockerfile 看起来是这样的:
FROM ubuntu:16.04
MAINTAINER Dockerfiles
# Install required packages and remove the apt packages cache when done.
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
...
# install uwsgi
RUN pip3 install uwsgi
# copy over requirements.txt file
COPY requirements.txt /home/docker/code/
# upgrade pip and install required python packages
RUN pip3 --no-cache-dir install -U pip
RUN pip3 --no-cache-dir install -r /home/docker/code/requirements.txt
# add (the rest of) our code
COPY ./app /home/docker/code/
# create a systemd unit file
COPY ./app.service /etc/systemd/system/ # Think the problem is here
# start the uwsgi service
RUN systemctl start app # This is not working
RUN systemctl enable app
# setup all the configfiles
COPY nginx_app /etc/nginx/sites-available/
# enable nginx server block
RUN ln -s /etc/nginx/sites-available/nginx_app /etc/nginx/sites-enabled
# validate syntax
CMD ["nginx", "-t"]
# restart nginx
RUN systemctl restart nginx
# allow nginx
RUN ufw allow 'Nginx Full'
然后是我的 app.service:
[Unit]
Description=uWSGI instance to serve app
After=network.target
[Service]
User=docker
Group=www-data
WorkingDirectory=/home/docker/code
ExecStart=/usr/local/bin/uwsgi --ini uwsgi.ini
[Install]
WantedBy=multi-user.target
nginx 配置
server {
listen 80;
server_name my_server_ip;
# max upload size
client_max_body_size 75M; # adjust to taste
location / {
include uwsgi_params;
uwsgi_pass unix:/home/docker/code/myproject.sock;
}
然后是我的 uwsgi.ini
[uwsgi]
module = wsgi:app
master = true
processes = 5
socket = app.sock
chmod-socket = 664
vacuum = true
die-on-term = true
但是当我尝试构建它时,我得到了这个错误
第 12 步:运行 systemctl start app
--->在79a22c2629db中运行
连接总线失败:没有这样的文件或目录
INFO[0022] 命令 [/bin/sh -c systemctl start app] 返回非零代码:1
我正在阅读,我认为问题出在 systemd 上。我应该使用supervisord。但我不知道该怎么做。
在“普通”服务器上,我可以运行这些命令并且它会工作,但在 docker 容器中无法工作。
我遇到的“唯一”问题是我必须使用 uwsgi 和 nginx 运行我的应用程序,但我不明白。
我在 Internet 上阅读了许多帖子和教程,也尝试更改 this project,但它仍然无法正常工作,我更喜欢使用我的 dockerfile(这个),因为这是我所理解的。
【问题讨论】:
-
在 Docker 容器中将应用程序作为 systemd 服务运行没有任何意义。你为什么这样做?
-
我想用 supervisord 运行它,但我不知道该怎么做。我是 docker 容器的新手,我知道的唯一方法是使用 systemd。
标签: python docker nginx flask uwsgi