一、下载alpine镜像

[root@DockerBrian ~]# docker pull alpine
Using default tag: latest
Trying to pull repository docker.io/library/alpine ...
latest: Pulling from docker.io/library/alpine
4fe2ade4980c: Pull complete
Digest: sha256:621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528
Status: Downloaded newer image for docker.io/alpine:latest
[root@docker43 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/alpine latest 196d12cf6ab1 3 weeks ago 4.41 MB

二、编写Dockerfile

  创建scrapy目录存放dockerfile文件

[root@DockerBrian ~]# mkdir /opt/alpineDockerfile/
[root@DockerBrian ~]# cd /opt/alpineDockerfile/
[root@DockerBrian alpineDockerfile]# mkdir scrapy && cd scrapy && touch Dockerfile
[root@DockerBrian alpineDockerfile]# cd scrapy/
[root@DockerBrian scrapy]# ll
总用量 4
-rw-r--r-- 1 root root 1394 10月 10 11:36 Dockerfile

  编写dockerfile文件

# 指定创建的基础镜像
FROM alpine # 作者描述信息
MAINTAINER alpine_python3_scrapy (zhujingzhi@123.com) # 替换阿里云的源
RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories && \
echo "http://mirrors.aliyun.com/alpine/latest-stable/community/" >> /etc/apk/repositories # 同步时间 # 更新源、安装openssh 并修改配置文件和生成key 并且同步时间
RUN apk update && \
apk add --no-cache openssh-server tzdata && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config && \
ssh-keygen -t rsa -P "" -f /etc/ssh/ssh_host_rsa_key && \
ssh-keygen -t ecdsa -P "" -f /etc/ssh/ssh_host_ecdsa_key && \
ssh-keygen -t ed25519 -P "" -f /etc/ssh/ssh_host_ed25519_key && \
echo "root:h056zHJLg85oW5xh7VtSa" | chpasswd # 安装Scrapy依赖包(必须安装的依赖包)
RUN apk add --no-cache python3 python3-dev gcc openssl-dev openssl libressl libc-dev linux-headers libffi-dev libxml2-dev libxml2 libxslt-dev openssh-client openssh-sftp-server # 安装环境需要pip包(这里的包可以按照需求添加或者删除)
RUN pip3 install --default-timeout=100 --no-cache-dir --upgrade pip setuptools pymysql pymongo redis scrapy-redis ipython Scrapy requests # 启动ssh脚本
RUN echo "/usr/sbin/sshd -D" >> /etc/start.sh && \
chmod +x /etc/start.sh # 开放22端口
EXPOSE 22 # 执行ssh启动命令
CMD ["/bin/sh","/etc/start.sh"]

  实现了容器可以SSH远程访问 基于Python3 环境安装的Scrapy,通过start.sh脚本启动SSH服务

三、创建镜像

  创建镜像

[root@DockerBrian scrapy]# docker build -t scrapy_redis_ssh:v1 .

  查看镜像

[root@DockerBrian scrapy]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
scrapy_redis_ssh v1 b2c95ef95fb9 4 hours ago 282 MB
docker.io/alpine latest 196d12cf6ab1 4 weeks ago 4.41 MB

四、创建容器

  创建容器(名字为scrapy10086 远程端口是映射宿主机10086端口)

docker run -itd --restart=always --name scrapy10086 -p 10086:22 scrapy_redis_ssh:v1

  查看容器

[root@DockerBrian scrapy]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7fb9e69d79f5 b2c95ef95fb9 "/bin/sh /etc/star..." 3 hours ago Up 3 hours 0.0.0.0:10086->22/tcp scrapy10086

  登录容器

[root@DockerBrian scrapy]# ssh root@127.0.0.1 -p 10086
The authenticity of host '[127.0.0.1]:10086 ([127.0.0.1]:10086)' can't be established.
ECDSA key fingerprint is SHA256:wC46AU6SLjHyEfQWX6d6ht9MdpGKodeMOK6/cONcpxk.
ECDSA key fingerprint is MD5:6a:b7:31:3c:63:02:ca:74:5b:d9:68:42:08:be:22:fc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[127.0.0.1]:10086' (ECDSA) to the list of known hosts.
root@127.0.0.1's password: # 这里的密码就是dockerfile中定义的 echo "root:h056zHJLg85oW5xh7VtSa" | chpasswd
Welcome to Alpine! The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <http://wiki.alpinelinux.org>. You can setup the system with the command: setup-alpine You may change this message by editing /etc/motd. 7363738cc96a:~#

五、测试

  创建个scrapy项目测试

7363738cc96a:~# scrapy startproject test
New Scrapy project 'test', using template directory '/usr/lib/python3.6/site-packages/scrapy/templates/project', created in:
/root/test You can start your first spider with:
cd test
scrapy genspider example example.com
7363738cc96a:~# cd test/
7363738cc96a:~/test# ls
scrapy.cfg test
7363738cc96a:~/test# cd test/
7363738cc96a:~/test/test# ls
__init__.py __pycache__ items.py middlewares.py pipelines.py settings.py spiders
7363738cc96a:~/test/test#

  测试成功

基于alpine用dockerfile创建的爬虫Scrapy镜像的更多相关文章

  1. 基于alpine用dockerfile创建的ssh镜像

    1.下载alpine镜像 [root@docker43 ~]# docker pull alpine Using default tag: latest Trying to pull reposito ...

  2. 基于alpine用dockerfile创建的tomcat镜像

    1.下载alpine镜像 [root@docker43 ~]# docker pull alpine Using default tag: latest Trying to pull reposito ...

  3. 基于alpine用dockerfile创建的nginx镜像

    1.下载alpine镜像 [root@docker43 ~]# docker pull alpine Using default tag: latest Trying to pull reposito ...

  4. 使用Dockerfile创建ssh服务的镜像02

    使用Dockerfile创建ssh服务的镜像02 1:创建工作目录---一个镜像的所有文件都放这个目录下 ubuntu@ubuntu:~$ mkdir sshd_ubuntu ubuntu@ubunt ...

  5. Docker使用Dockerfile创建Centos(tomcat+jdk)镜像

    原文链接:https://blog.csdn.net/qq_37936542/article/details/80824389 Docker构建镜像的方法主要有两种:    (1)使用docker c ...

  6. Docker学习笔记_使用Dockerfile创建flask的一个镜像

    一.实验环境 1.宿主机OS:Win10 64位 2 .虚拟机OS:Ubuntu18.04 64位    虚拟机名称:Ubuntu18VM1   虚拟机IP:192.168.8.25 3.账号:doc ...

  7. 根据Dockerfile创建docker dotnet coer 镜像

    那我们先来看看Dockerfile文件内容,注意这个文件是没后缀名的. #依赖原始的镜像,因为我们是要创建dotnet coer镜像,所以我就用了官方给的镜像[microsoft/dotnet:lat ...

  8. 用dockerfile创建jmeter的docker镜像

    网上多是创建docker镜像是从jmeter官方下载jmeter的tgz包 今天我们用本地已经下载好的tgz包. 以下是dockerfile FROM java:8 ENV http_proxy &q ...

  9. python爬虫Scrapy(一)-我爬了boss数据

    一.概述 学习python有一段时间了,最近了解了下Python的入门爬虫框架Scrapy,参考了文章Python爬虫框架Scrapy入门.本篇文章属于初学经验记录,比较简单,适合刚学习爬虫的小伙伴. ...

随机推荐

  1. Win7 MinGW环境测试SDL2.0.3

    下载MinGW版的文件 http://www.libsdl.org/release/SDL2-devel-2.0.3-mingw.tar.gz 解压放到mysys下面 运行Makefile mysys ...

  2. vba遗传算法之非一致性突变

    http://www.docin.com/p-959323141-f4.html Sub 非一致性变异() Dim totalGenerate As Integer, currentGenerate ...

  3. Promise.all函数的使用

    Promise.all([this.getCity('guess'),this.getCity('hot'),this.getCity('group')]).then(res=>{ // con ...

  4. matchesSelector()方法

    let result = element.matches(selectorString); result 的值为 true 或 false. selectorString 是个css选择器字符串. i ...

  5. 使用mockserver来进行http接口mock

    转载自:https://blog.csdn.net/heymysweetheart/article/details/52227379:(注,这个不是很符合我的要求,它主要的作用是可以通过简单的代码就能 ...

  6. 20155205 2016-2017-2《Java程序设计》课程总结

    20155205 2016-2017-2<Java程序设计>课程总结 目录 一.每周作业链接汇总 二.实验报告链接汇总 三.博客中的经验与收获 - 自认为写得最好一篇博客是?为什么? - ...

  7. C#窗体操作的小技巧

    窗体在屏幕居中 ) - (), (Screen.GetBounds() - (), this.Width, this.Height, BoundsSpecified.Location);

  8. matlab矢量场数值可视化(动态数值模拟)

    https://blog.csdn.net/eric_e/article/details/81294092 D3.js实现数据可视化 三维可视化 风场可视化(数据插值):风场是动态变化的,实时刷新的, ...

  9. How to fix "http error 403.14 - forbidden" in IIS7

    If you encounter the following error: "http error 403.14 - forbidden. The Web server is configu ...

  10. POJ2429--GCD & LCM Inverse (UNSOLVED)

    Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and t ...