使用docker部署Django程序遇到了问题,紧急求助!!!

冲冠一怒为红薯 发布于 2017/05/09 09:58
阅读 402
收藏 0

 

我使用conda管理python开发环境
按照这里的教程:https://www.qcloud.com/commun...
各种错误,请问用conda管理的Django程序怎么部署到docker的?

详细信息如下:分为三个镜像,mysql,nginx,web(uwsgi+Django).

目录结构:

mysql->start.sh 内容如下:

#!/bin/bash 
#

echo "---------------start mysql image-------------------"
docker run --name mysql \
-v $(pwd)/conf.d:/etc/mysql/conf.d \
-v $(pwd)/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 3307:3306 \
-d daocloud.io/mysql:5.6.30 \
--character-set-server=utf8 --collation-server=utf8_unicode_ci
sleep 15

nginx->nginx-conf->backend_nginx.conf 内容如下:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    # access_log /var/log/nginx/access.log;
    # error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    # backend_nginx.conf

    # the upstream component nginx needs to connect to
    upstream django {
        server unix:/usr/src/backend/backend/backend.sock; # for a file socket
        # server 127.0.0.1:8000; # for a web port socket (we'll use this first)
    }
    # configuration of the server
    server {
        # the port your site will be served on
        listen      80;
        # the domain name it will serve for
        server_name 192.168.100.20; # substitute your machine's IP address or FQDN
        charset     utf-8;
    
        # access_log      /usr/src/backend/log/nginx_access.log;
        error_log       /usr/src/backend/log/nginx_error.log;
    
        # max upload size
        client_max_body_size 75M;   # adjust to taste
    
        # Django media
        # location /media  {
        #     alias /path/to/your/mysite/media;  # your Django project's media files - amend as required
        # }
    
        location /static {
            alias /usr/src/backend/static; # your Django project's static files - amend as required
        }
    
        # Finally, send all non-media requests to the Django server.
        location / {
            uwsgi_pass  django;
            include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
        }
    }
}


#mail {
#    # See sample authentication script at:
#    # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#    # auth_http localhost/auth.php;
#    # pop3_capabilities "TOP" "USER";
#    # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#    server {
#        listen     localhost:110;
#        protocol   pop3;
#        proxy      on;
#    }
# 
#    server {
#        listen     localhost:143;
#        protocol   imap;
#        proxy      on;
#    }
#}

nginx->Dockerfile 内容如下:


FROM daocloud.io/nginx

MAINTAINER tianfeiyu <www.tianfeiyu.com>

RUN rm /etc/nginx/conf.d/default.conf
ADD nginx-conf/ /etc/nginx/conf.d/

nginx->start.sh 内容如下:

#!/bin/bash 
#
docker build -t nginx .
docker run --name nginx-server \
--link django:web \
-v /www/static \
--volumes-from django \
-p 8888:80 \
-d nginx
sleep 15

web->Dockerfile 内容如下:


# 基础镜像
FROM daocloud.io/python:3.4.5

# 维护者信息
MAINTAINER tianfeiyu <www.tianfeiyu.com>

ADD backend.tar.gz /usr/src/ 

# app 所在目录
WORKDIR /usr/src/backend

# 安装miniconda,配置conda 环境


RUN apt-get update && apt-get install -y curl vim wget 

RUN pip install uwsgi -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

ADD backend_uwsgi.ini /usr/src/backend/

RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh && \
    wget --quiet http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh && \
    /bin/bash ./Miniconda-latest-Linux-x86_64.sh -b -p /opt/conda && \
    rm ./Miniconda-latest-Linux-x86_64.sh

ENV PATH /opt/conda/bin:$PATH

ADD environment.yml /usr/src/backend/environment.yml

RUN conda env create -f /usr/src/backend/environment.yml

RUN source activate webback

web->start.sh 内容如下:

#!/bin/bash 
#
docker exec -d mysql mysql -uroot -p123456 -e "create database blog;"
docker build -t feiyu/django-app .
docker run --name django \
-v /usr/src/backend \
-v /usr/src/backend/static \
--link mysql:mysql \
-p 12000:8000 \
-d feiyu/django-app uwsgi --ini /usr/src/backend/backend_uwsgi.ini
sleep 15
#-d feiyu/django-app /usr/local/bin/gunicorn backend.wsgi:application -w 1 -b :8000

总的docker-start.sh:

#!/bin/bash
#
cd mysql  
echo "start mysql----------------"
./start.sh

cd ../web 
echo "start web ---------------------"
./start.sh
# ./init_django.sh

cd ../nginx
echo "start nginx-------------------"
./start.sh

运行docker-start.sh后的记录如下:

start mysql----------------
---------------start mysql image-------------------
214f2b2e9dd2b37642b8e513ad613006f46b7a53828fac7dab71012b651f404f
start web ---------------------
Sending build context to Docker daemon 7.946 MB

Step 1/12 : FROM daocloud.io/python:3.4.5
 ---> 9dad7c7d977a
Step 2/12 : MAINTAINER tianfeiyu <www.tianfeiyu.com>
 ---> Using cache
 ---> 3e145a158b8d
Step 3/12 : ADD backend.tar.gz /usr/src/
 ---> Using cache
 ---> 7e1d8e2a7ddd
Step 4/12 : WORKDIR /usr/src/backend
 ---> Using cache
 ---> 4ed2fb4167c2
Step 5/12 : RUN apt-get update && apt-get install -y curl vim wget
 ---> Using cache
 ---> 8618c161de6a
Step 6/12 : RUN pip install uwsgi -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
 ---> Using cache
 ---> eefb7ee5655e
Step 7/12 : ADD backend_uwsgi.ini /usr/src/backend/
 ---> Using cache
 ---> 6db40e88dc0d
Step 8/12 : RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh &&     wget --quiet http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh &&     /bin/bash ./Miniconda-latest-Linux-x86_64.sh -b -p /opt/conda &&     rm ./Miniconda-latest-Linux-x86_64.sh
 ---> Using cache
 ---> 71d3059af7bd
Step 9/12 : ENV PATH /opt/conda/bin:$PATH
 ---> Using cache
 ---> f3585a7f104d
Step 10/12 : ADD environment.yml /usr/src/backend/environment.yml
 ---> Using cache
 ---> f64d240e9f2b
Step 11/12 : RUN conda env create -f /usr/src/backend/environment.yml
 ---> Running in 011e6f414ee0
[91mError: Can't process without a name
Please install nbformat:
    conda install nbformat
/usr/src/backend/environment.yml is not a valid yaml file.
Environment with requierements.txt file needs a name
[0m84fd8042afa8e019f532b402f3044a24aaa643f950ff273a6d83326b90a82628
start nginx-------------------
Sending build context to Docker daemon 9.216 kB

Step 1/4 : FROM daocloud.io/nginx
 ---> 5766334bdaa0
Step 2/4 : MAINTAINER tianfeiyu <www.tianfeiyu.com>
 ---> Using cache
 ---> ea94eefa9d44
Step 3/4 : RUN rm /etc/nginx/conf.d/default.conf
 ---> Using cache
 ---> 05285ed99712
Step 4/4 : ADD nginx-conf/ /etc/nginx/conf.d/
 ---> Using cache
 ---> 7099f8c1341a
Successfully built 7099f8c1341a
99427379f1f4b1119c25bf1af648f9324d8168ac8dcb167a49f7acc5bafa6877

返回结果是 :

The command '/bin/sh -c conda env create -f /usr/src/backend/environment.yml' returned a non-zero code: 1
docker: Error response from daemon: Cannot link to a non running container: /django AS /nginx-server/web.

运行 docker ps -a 查看结果是:

CONTAINER ID        IMAGE                      COMMAND                  CREATED              STATUS                     PORTS                    NAMES
99427379f1f4        nginx                      "nginx -g 'daemon ..."   About a minute ago   Created                                             nginx-server
84fd8042afa8        feiyu/django-app           "uwsgi --ini /usr/..."   2 minutes ago        Exited (0) 2 minutes ago                            django
011e6f414ee0        f64d240e9f2b               "/bin/sh -c 'conda..."   2 minutes ago        Exited (1) 2 minutes ago                            lucid_lewin
214f2b2e9dd2        daocloud.io/mysql:5.6.30   "docker-entrypoint..."   2 minutes ago        Up 2 minutes               0.0.0.0:3307->3306/tcp   mysql

各种失败,怎么都不通,请大家帮帮我,顺便说一下,我是使用conda管理开发环境的,怎么把conda加到镜像里我始终都搞不通。

附带我的environment.yml:

name: webback
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
dependencies:
- django=1.10.5=py34_0
- openssl=1.0.2k=1
- pip=9.0.1=py34_1
- python=3.4.5=0
- readline=6.2=2
- setuptools=27.2.0=py34_0
- sqlite=3.13.0=0
- tk=8.5.18=0
- wheel=0.29.0=py34_0
- xz=5.2.2=1
- zlib=1.2.8=3
- pymysql=0.7.9=py34_0
- pip:
  - django-guardian==1.4.8
  - jsonfield==2.0.1
  - six==1.10.0
  - uwsgi==2.0.15
prefix: /home/yangtz/anaconda3/envs/webback

求大神指点啊!!!!

加载中
返回顶部
顶部