docker 部署scrapy项目

1.新建Dockerfile文件

FROM python:3.6

# install google chrome
#RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
#RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
#RUN apt-get -y update
#RUN apt-get install -y google-chrome-stable
#
## install chromedriver
#RUN apt-get install -yqq unzip
#RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
#RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/


WORKDIR /usr/src/app
ADD . /usr/src/app

# install requirements
RUN pip install -r requirements.txt

CMD ["python3", "start.py"]

 

2.新建requirements.txt统一环境

 

 

3.新建docker镜像

/coco_spiders

docker build -t coco_spiders .

运行 

docker run coco_spiders

 

4.在docker中访问本机mongo,需要修改配置文件

cd /usr/local/etc/mongod.conf bindIp修改为0.0.0.0

然后重启mongo服务才生效 mongod --config /usr/local/etc/mongod.conf

在docker中就可以直接通过本机ip访问mongo数据库了

 

posted @ 2021-03-01 20:35  LeeJuly  阅读(468)  评论(0编辑  收藏  举报