使用Docker和mongodb,redis的简单记录
docker搜索redis:docker search redis
docker安装mongodb命令:docker pull mongo
Docker显示所有正在运行的进程:docker ps -l
Docker显示镜像列表命令:docker images
Docker运行 mongodb:docker run --name mongo1 -p 21117:27017 -d mongo --noprealloc --smallfiles --auth
Docker 进入容器:docker exec -it mongo1 bash
Docker 进入mongo :mongo 切换到admin库: use admin
Docker mongodb 创建用户:db.createUser({ user: "root", pwd: "mongo", roles: [{ role: "userAdminAnyDatabase", db: "admin" }] })
Docker mongodb 退出:exit
Docker 登录进入:mongo admin -u root -p root
创建库:
use doushang
创建某个库的用户:
db.createUser(
{
user: "root",
pwd: "root",
roles: [ { role: "readWrite", db: "doushang" }, ]
}
)
安装redis: docker pull redis
运行: docker run -p 6379:6379 -d redis:latest redis-server
最后修改配置cfg:
# mongodb
CFG_MONGODB_URL = mongodb://root:root@192.168.1.154:27017/?authSource=admin
CFG_MONGODB_DB = doushang
CFG_MONGODB_COLL_COMMODITY = commodity
CFG_MONGODB_COLL_PERSON = person
# redis
CFG_REDIS_HOST = 192.168.1.154
CFG_REDIS_PORT = 6379
CFG_REDIS_DB = 1
CFG_REDIS_PWD =
运行代码:
docker run -it -v /Users/shoudao/Documents/gitsource/toobigdata/BigDataSpider:/opt/project registry.cn-hangzhou.aliyuncs.com/zwdc/python_spider:toobigdata_spider
docker container stop 爬虫容器id
打包当前目录到docker镜像:
docker build -t apitest .
镜像显示:docker images
运行镜像:docker run -t 镜像id
执行镜像后:可以看到容器 docker container ls
删除容器:docker rm 容器id
删除镜像:docker rmi 镜像id