今后会发布反爬虫教程,点波关注不迷路哦。如果文章有帮助,点颗星鼓励一下。
如果没有安装docker的可以参考:Windows 10 下安装使用Docker
https://github.com/MaNongXiaoGang/docker_python3.6
第一个Dockerfile文件,修改下载源,解决 apt-get 和 pip 下载超时的问题
FROM python:3.6
MAINTAINER MaNongXiaoGang
ENV CODE /usr/src/code
RUN mkdir -p $CODE
# 设置工作目录
WORKDIR $CODE
# 下一级镜像执行
ONBUILD COPY ./requirements.txt $CODE
ONBUILD RUN pip install -U pip --default-timeout=10000 && \
pip install --no-cache-dir -r requirements.txt --default-timeout=10000
# 更改pip源
ADD ./pip.conf $CODE
# 把当前目录文件添加到工作目录
ADD ./sources.list $CODE
# 修改apt-get源
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
mv sources.list /etc/apt/ && \
sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list && \
mkdir /root/.pip/ && \
mv pip.conf /root/.pip/pip.conf && \
rm -rf /var/lib/apt/lists/* && \
apt-get update && \
apt-get install -y --no-install-recommends\
# 下载安装 sudo,不然用 Pycharm 创建 Django 项目时会报错
sudo \
vim \
# 安装ssh-server,远程连接
openssh-server && \
# 设置 root 用户密码
echo 'root:qq123456' | chpasswd && \
# 注意在 PermitRootLogin 前加 #,因为 sshd_config 文件里该参数是被注释的
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
sed 's@sessions*requireds*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd && \
echo "export VISIBLE=now" >> /etc/profile && \
# 重启 SSH 激活配置
service ssh restart
# 开放端口,多个以空格隔开
EXPOSE 22 5000
CMD ["/bin/bash"]
# FROM python:3.6 可以修改其它源镜像,我这里用python3.6做机器学习
# echo 'root:qq123456' | chpasswd 密码可修改,要记住密码,后面远程连接需要
# EXPOSE 22 5000 需要开放的端口
FROM python36:python3.6
MAINTAINER MaNongXiaoGang
[global]
trusted-host=pypi.tuna.tsinghua.edu.cn
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
docker build -t "python36:python3.6" -f Dockerfile .
cd MachineLearning/
docker build -t "machinelearning/python3.6" -f Dockerfile .
docker run -it -v /home/lfg/Desktop/code:/usr/src/code/data -p 10001:22 machinelearning/python3.6
/home/lfg/Desktop/code 修改成你主机的路径,当数据卷,存放代码。 注意这里不修改可能会报错,这个路径是我的主机路径。
注意:
-v 参数是挂载数据卷,这里需要修改成你主机的代码路径。
格式: -v 主机路径: 容器路径
注意:
Local Path
填写你主机代码路径,或者你准备在某个路径写代码,就填哪个路径。 Remote Path
填写docker数据卷路径,上面有设置的:/usr/src/code/data