Docker国内下载:地址
curl -sSL https://get.daocloud.io/docker | sh
加速器:地址直接拷贝执行
新建一个scrapyd.conf
文件,填写配置内容,默认使用官网上的就可以。
官网配置文件:链接
[scrapyd]
eggs_dir = eggs
logs_dir = logs
items_dir =
jobs_to_keep = 5
dbs_dir = dbs
max_proc = 0
max_proc_per_cpu = 10
finished_to_keep = 100
poll_interval = 5.0
bind_address = 0.0.0.0
http_port = 6800
debug = off
runner = scrapyd.runner
application = scrapyd.app.application
launcher = scrapyd.launcher.Launcher
webroot = scrapyd.website.Root
[services]
schedule.json = scrapyd.webservice.Schedule
cancel.json = scrapyd.webservice.Cancel
addversion.json = scrapyd.webservice.AddVersion
listprojects.json = scrapyd.webservice.ListProjects
listversions.json = scrapyd.webservice.ListVersions
listspiders.json = scrapyd.webservice.ListSpiders
delproject.json = scrapyd.webservice.DeleteProject
delversion.json = scrapyd.webservice.DeleteVersion
listjobs.json = scrapyd.webservice.ListJobs
daemonstatus.json = scrapyd.webservice.DaemonStatus
➜ Scrapyd vi requirements.txt
requests
selenium
aiohttp
beautifulsoup4
pyquery
pymysql
redis
pymongo
flask
scrapy
scrapyd
scrapyd-client
scrapy-redis
scrapy-splash
fake-useragent
➜ Scrapyd ls
scrapyd.conf requirements.txt
当前目录下有两个文件,一个是scrapyd的配置文件,另一个是pip下载模块的文件。
编写Dockerfile文件
➜ Scrapyd touch Dockerfile
➜ Scrapyd vi Dockerfile
FROM python:3.6
ADD . /code
WORKDIR /code
COPY ./scrapyd.conf /etc/scrapyd/
EXPOSE 6800
RUN pip3 install -r requirements.txt
CMD scrapyd
.
代表当前路径,/code
代表虚拟容器的路径。scrapyd.conf
拷贝到虚拟容器中/etc/scrapyd/
。构建镜像
docker build -t scrapyd:latest .
运行
docker run -d -p 6800:6800 scrapyd
我们打开 http://localhost:6800 就能看到Scrapyd服务。
首先为镜像修改标签,hubogle代表自己的Docker Hub用户名,这里是我的名字。
docker tag scrapyd:latest hubogle/scrapyd:latest
然后Push
项目到镜像仓库。
docker push hubogle/scrapyd:latest
下载镜像到本机
docker pull hubogle/scrapyd:latest
docker run -d -p 6800:6800 hubogle/scrapyd:latest
我在执行docker login
登录命令的时候,报错误。
denied: requested access to the resource is denied
解决方法:
mv /usr/local/bin/docker-credential-osxkeychain docker-credential-osxkeychain.bak
docker 启动和停止命令。
[root@VM_0_10_centos ~]# service docker start
Redirecting to /bin/systemctl start docker.service
[root@VM_0_10_centos ~]# service docker stop
Redirecting to /bin/systemctl stop docker.service
我们在部署分布式的时候,其他机器只要安装dokcer直接pull镜像就可以了。
创建完Docker后配合Gerapy管理更方便:地址