Docker快速构建开发测试环境 | 8lovelife's life
0%

Docker快速构建开发测试环境

简单记录下我在开发过程中,如何快速构建调试环境

RedisService

  • 下载Redis image
1
docker pull redis
  • 启动Redis
1
2
3
4
docker run --restart=always -d -ti --name redisService \
-v /home/core/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf \
-v /home/core/redis/data:/data -p 16379:6379 redis \
redis-server /usr/local/etc/redis/redis.conf
  • 登录Redis
1
docker exec -it redisService redis-cli --raw -a redis

MysqlService

  • 下载Mysql image
1
docker pull mysql
  • 启动Mysql
1
2
3
4
docker run --restart=always -it --name mysqlService \
-v /home/core/mysql/data/:/var/lib/mysql \
-v /home/core/mysql/conf.d:/etc/mysql/conf.d \
-p 13306:3306 -e MYSQL\_ROOT\_PASSWORD=12345 -d mysql

MongoService

  • 下载Mongo image
1
docker pull mongo
  • 启动MongoDB
1
2
3
docker run -ti --restart=always --name mongoService \
-v /home/core/mongo/data:/data/db -p 27017:27017 \
-d mongo --auth
  • 登录Mongo,建立用户
1
2
3
docker exec -it mongoService mongo admin;
db.createUser({user:'admin',pwd:'admin',roles:[{role:'root',db:'admin'}]});
db.auth('admin','admin');
  • 创建collection dmz_inward下的普通用户
1
2
use dmz_inward;
db.createUser({user:'dmz',pwd:'dmz',roles: [{role:'readWrite',db:'dmz_inward'}]});

NginxService

  • 下载Nginx image
1
docker pull nginx
  • 启动Nginx
1
2
3
4
docker run -it --restart=always --name nginxService -p 80:80 \
-v /home/core/yourResources: /usr/share/nginx/html:ro \
-v /logs:/var/log/nginx \
-v /home/core/conf/nginx/nginx.conf:ro -d nginx

RabbitmqService

  • 下载rabbitmq:3-management
1
docker pull rabbitmq:3-management
  • 启动rabbitmq:3-management
1
2
3
4
5
6
docker run --restart=always --name rabbitmqService \
--hostname fRabbit \
-p 5672:5672 -p 15672:15672 \
-v /home/core/rabbitmq/data:/var/lib/rabbitmq/mnesia/rabbit@fRabbit \
-v /home/core/rabbitmq/conf/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro \
-d rabbitmq:3-management
  • rabbitmq.config配置
1
2
3
4
5
6
7
8
9
[ { rabbit, [
{ loopback_users, [ ] },
{ tcp_listeners, [ 5672 ] },
{ default_user, <<"dmz">> }, #用户名
{ default_pass, <<"dmz">> }, #密码
{ ssl_listeners, [ ] },
{ hipe_compile, false }
]
},{rabbitmq_management, [{listener, [{port, 15672}]}]} ]

image


Portainer

漂亮的docker容器管理界面

  • 下载portainer image
1
docker pull portainer/portainer`
  • 启动Portainer
1
2
docker run -d --restart=always --name=portainer \
-p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer

image

Kafka

Kafka

参考

Docker Hub

It’s not like he’s dead or anything. He’s just… different. - Christopher Johnson

District 9