准备工作:
- 安装docker https://www.docker.com/docker-ubuntu 选择ce版本
- 通过docker pull 下载基础镜像,ubuntu16.04, redis, mysql
- docker pull ubuntu16.04
- docker pull redis
- docker pull mysql
- 启动一个redis容器:docker run -it --name=redis_container redis:latest /bin/bash
- 启动一个ubuntu16.04容器:安装,pip, python, scrapy_redis, mysqldb, redis, 等然后生成一个新镜像:scrapy_redis:0.3
- 通过scrapy_redis:0.3 启动一个新镜像 docker run --name scrapy-1 --link redis_container:redis -itd scrapy_redis:0.3 /bin/bash
- 然后redis_container容器中启动redis服务:redis-server 先用默认的方式启动,具体的配置以后再加上。
- 这个时候在scrapy-1容器中测试是否能够访问:redis数据库。eg:
renjg@847271d2a6ac:~$ python Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import redis >>> r = redis.Redis(host='redis',port=6379) >>> r.set('ren','jingui') True >>> r.get('ren') 'jingui' >>>
资料收集:python 操作redis,http://debugo.com/python-redis/