我正在尝试Dockerize
Django Web App
Docker
Linux Ubuntu 16.04
,以便将其迁移到我的生产服务器。
此服务器基于Apache2
,我想将DatasystemsCORE
├── API_GED
├── Authentification
├── Configurations
├── DatasystemsCORE
├── App1
├── App2
├── App3
├── App4
├── lib
├── static
├── templates
├── wsgi.conf
├── docker-compose.yml
├── Dockerfile
├── manage.py
├── requirements.txt
├── start.sh
安装到我的容器中。
我找到了使用Docker的不同方式,特别是这个github存储库:https://github.com/ramkulkarni1/django-apache2-docker
但有关将Docker与Django和Apache2配置的文档关于新生产服务器的文档太少。
-------------------------------------------- -------------------------------------------------- -------------------------------------- 第一部分 - 我的树项目: -------------------------------------------------- -------------------------------------------------- --------------------------------
FROM ubuntu
RUN apt-get update
RUN apt-get install -y apt-utils vim curl apache2 apache2-utils
RUN apt-get -y install python3 libapache2-mod-wsgi-py3
RUN ln /usr/bin/python3 /usr/bin/python
RUN apt-get -y install python3-pip
RUN ln /usr/bin/pip3 /usr/bin/pip
RUN pip install --upgrade pip
RUN pip install django ptvsd
ADD ./demo_site.conf /etc/apache2/sites-available/000-default.conf
EXPOSE 80 3500
CMD ["apache2ctl", "-D", "FOREGROUND"]
FROM python:3.6
ENV PYTHONUNBUFFERED 1
ADD ./requirements.txt /requirements.txt
RUN pip install -U pip &&
LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "pip install -r /requirements.txt --no-cache-dir" RUN mkdir /code WORKDIR /code ADD ./src .
EXPOSE 8000
ADD ./start.sh /start.sh
RUN chmod +x /start.sh
-------------------------------------------- -------------------------------------------------- -------------------------------------- 第二部分 - 根据Docker的文件: -------------------------------------------------- -------------------------------------------------- --------------------------------
所以我创建了一个 Dockerfile :
version: "2"
services:
django-apache2:
build: .
container_name: django-apache2
ports:
- '8005:80'
- '3500:3500'
- '8006:81'
volumes:
- $PWD/www:/var/www/html
db:
image: mariadb
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=root
- MYSQL_PASSWORD=root
- MYSQL_DATABASE=DatasystemsCORE
ports:
- "3306:3306"
volumes:
- db-persistance:/var/lib/mysql
django-app:
build: .
environment:
- SECRET_KEY=django-app
- DATABASE_NAME=DatasystemsCORE
- DATABASE_USER=django
- DATABASE_PASSWORD=django
- DATABASE_HOST=db
entrypoint: /start.sh
command: python3 /code/manage.py runserver 0.0.0.0:8005
depends_on:
- db
然后,我有一个 docker-compose.yml 文件:
ADD #!/bin/bash
python3 /code/manage.py migrate && python3 /code/manage.py collectstatic --noinput
exec "$@"
我也创建了一个start.sh文件:
Apache2
为了设置WSGIPythonPath /var/www/html/DatasystemsCORE
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/DatasystemsCORE
Alias /static "/var/www/html/DatasystemsCORE/static"
<Directory /var/www/html/DatasystemsCORE/static>
Require all granted
</Directory>
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
WSGIScriptAlias / /var/www/html/DatasystemsCORE/DatasystemsCORE/wsgi.py
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
配置,我有 wsgi.conf 文件:
docker-compose run web django-admin.py startproject DatasystemsCORE DatasystemsCORE
最后我有一个 requirements.txt 文件,其中包含根据我的Django项目的所有依赖项。
-------------------------------------------- -------------------------------------------------- -------------------------------------- 第三部分 - 创建dockerizing图像并将图像构建到我的prod服务器: -------------------------------------------------- -------------------------------------------------- --------------------------------
在这部分我有一些问题。 我不知道我的docker文件是否写得很好。
然后,我不知道我必须执行什么命令。
我试过了:
ERROR: No such service: web
我得到:{{1}}
我的过程很好,或者我必须做出与众不同的事情?