使用/ Docker、nginx 和 django 服务大型数据集
Serve large dataset w/ Docker, nginx, & django
我正在进行一个涉及大型视频数据集(数百 GB,在不久的将来可能是多个 TB)的研究项目。我对 linux、系统管理员和设置服务器相当陌生,所以请多多包涵。我已经提供了很多信息,如果还有其他有用的信息,请告诉我。
我正在使用 Ubuntu、Docker(带 docker-compose)、nginx、Python3.5 和 django 1.10
上传大型 (60GB) 数据集会导致以下错误:
$ sudo docker-compose build
postgres uses an image, skipping
Building django
Step 1 : FROM python:3.5-onbuild
# Executing 3 build triggers...
Step 1 : COPY requirements.txt /usr/src/app/
---> Using cache
Step 1 : RUN pip install --no-cache-dir -r requirements.txt
---> Using cache
Step 1 : COPY . /usr/src/app
ERROR: Service 'django' failed to build: Error processing tar file(exit status 1): write /usr/src/app/media/packages/video_3/video/video_3.mkv: no space left on device
我的文件在一个有 500GB 可用空间的驱动器上,而当前数据集只有 ~60GB。
我找到了 this discussion on container size。也许我误解了 Docker,但我相信我只是想让我的体积更大,而不是容器本身,所以这似乎不合适。它也不使用 docker-compose,所以我不清楚如何在我当前的设置中实现它。
需要说明的是,在 this question 的帮助下,我能够使用少量测试数据提供静态文件和媒体文件。 (我不清楚它们是从 django 容器还是 nginx 容器提供服务,因为数据通过 ssh 出现在两个容器中)
如何让我的设置处理如此大量的数据?我希望以后能够上传额外的数据,所以如果存在一个解决方案可以做到这一点而不必一直重建卷,那就太棒了。
我的设置
目录结构
film_web
├── docker-compose.yml
├── Dockerfile
├── film_grammar
│ ├── #django code lives here
├── gunicorn_conf.py
├── media
│ ├── #media files live here
├── nginx
│ ├── Dockerfile
│ └── nginx.conf
├── requirements.txt
└── static
├── #static files live here
docker-compose.yml
nginx:
build: ./nginx
volumes:
- ./media:/usr/src/app/film_grammar/media
- ./static:/usr/src/app/film_grammar/static
links:
- django
ports:
- "80:80"
volumes_from:
- django
django:
build: .
volumes:
- ./film_grammar:/usr/src/app/film_grammar
expose:
- "8000"
links:
- postgres
postgres:
image: postgres:9.3
film_web Docker文件
From python:3.5-onbuild
ENV DJANGO_CONFIGURATION Docker
CMD ["gunicorn", "-c", "gunicorn_conf.py", "--chdir", "film_grammar", "fg.wsgi:application", "--reload"]
VOLUME /home/alexhall/www/film_web/static
VOLUME /home/alexhall/www/film_web/media
nginx Docker文件:
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
server {
listen 80;
server_name film_grammar_server;
access_log /dev/stdout;
error_log /dev/stdout info;
location /static {
alias /usr/src/app/film_grammar/static/;
}
location /media {
alias /usr/src/app/film_grammar/media/;
}
location / {
proxy_pass http://django:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
在此先感谢您的帮助!
build
首先从上下文目录(在您的例子中是 .
)创建一个 tarball,然后将该 tarball 发送到服务器。 tarball 是在我相信的 tmp 目录中创建的,这可能就是为什么你在尝试构建时 运行 超出 space 的原因。
当您处理大型数据集时,推荐的方法是使用卷。您可以使用绑定安装卷从主机安装文件。
由于您使用卷提供数据,因此您需要将其从图像上下文中排除。为此,请在 .
目录中创建一个 .dockerignore
。在该文件中添加所有具有大数据的路径(.git
、media
、static
)。
一旦您忽略了构建应该工作的大目录。
我正在进行一个涉及大型视频数据集(数百 GB,在不久的将来可能是多个 TB)的研究项目。我对 linux、系统管理员和设置服务器相当陌生,所以请多多包涵。我已经提供了很多信息,如果还有其他有用的信息,请告诉我。
我正在使用 Ubuntu、Docker(带 docker-compose)、nginx、Python3.5 和 django 1.10
上传大型 (60GB) 数据集会导致以下错误:
$ sudo docker-compose build
postgres uses an image, skipping
Building django
Step 1 : FROM python:3.5-onbuild
# Executing 3 build triggers...
Step 1 : COPY requirements.txt /usr/src/app/
---> Using cache
Step 1 : RUN pip install --no-cache-dir -r requirements.txt
---> Using cache
Step 1 : COPY . /usr/src/app
ERROR: Service 'django' failed to build: Error processing tar file(exit status 1): write /usr/src/app/media/packages/video_3/video/video_3.mkv: no space left on device
我的文件在一个有 500GB 可用空间的驱动器上,而当前数据集只有 ~60GB。
我找到了 this discussion on container size。也许我误解了 Docker,但我相信我只是想让我的体积更大,而不是容器本身,所以这似乎不合适。它也不使用 docker-compose,所以我不清楚如何在我当前的设置中实现它。
需要说明的是,在 this question 的帮助下,我能够使用少量测试数据提供静态文件和媒体文件。 (我不清楚它们是从 django 容器还是 nginx 容器提供服务,因为数据通过 ssh 出现在两个容器中)
如何让我的设置处理如此大量的数据?我希望以后能够上传额外的数据,所以如果存在一个解决方案可以做到这一点而不必一直重建卷,那就太棒了。
我的设置
目录结构
film_web
├── docker-compose.yml
├── Dockerfile
├── film_grammar
│ ├── #django code lives here
├── gunicorn_conf.py
├── media
│ ├── #media files live here
├── nginx
│ ├── Dockerfile
│ └── nginx.conf
├── requirements.txt
└── static
├── #static files live here
docker-compose.yml
nginx:
build: ./nginx
volumes:
- ./media:/usr/src/app/film_grammar/media
- ./static:/usr/src/app/film_grammar/static
links:
- django
ports:
- "80:80"
volumes_from:
- django
django:
build: .
volumes:
- ./film_grammar:/usr/src/app/film_grammar
expose:
- "8000"
links:
- postgres
postgres:
image: postgres:9.3
film_web Docker文件
From python:3.5-onbuild
ENV DJANGO_CONFIGURATION Docker
CMD ["gunicorn", "-c", "gunicorn_conf.py", "--chdir", "film_grammar", "fg.wsgi:application", "--reload"]
VOLUME /home/alexhall/www/film_web/static
VOLUME /home/alexhall/www/film_web/media
nginx Docker文件:
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
server {
listen 80;
server_name film_grammar_server;
access_log /dev/stdout;
error_log /dev/stdout info;
location /static {
alias /usr/src/app/film_grammar/static/;
}
location /media {
alias /usr/src/app/film_grammar/media/;
}
location / {
proxy_pass http://django:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
在此先感谢您的帮助!
build
首先从上下文目录(在您的例子中是 .
)创建一个 tarball,然后将该 tarball 发送到服务器。 tarball 是在我相信的 tmp 目录中创建的,这可能就是为什么你在尝试构建时 运行 超出 space 的原因。
当您处理大型数据集时,推荐的方法是使用卷。您可以使用绑定安装卷从主机安装文件。
由于您使用卷提供数据,因此您需要将其从图像上下文中排除。为此,请在 .
目录中创建一个 .dockerignore
。在该文件中添加所有具有大数据的路径(.git
、media
、static
)。
一旦您忽略了构建应该工作的大目录。