启动docker: systemctl start docker 注:常见命令见macro/spring-cloud-demo中的docker.md
安装地址:/usr/local/bin/docker-compose
设置为可执行:sudo chmod +x /usr/local/bin/docker-compose
测试是否安装成功:docker-compose --version
docker pull mysql:5.7
docker run -p 3306:3306 --name mysql \ -v /mydata/mysql/log:/var/log/mysql \ -v /mydata/mysql/data:/var/lib/mysql \ -v /mydata/mysql/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=123456 \ -d mysql:5.7
参数说明
- -p 3306:3306:将容器的3306端口映射到主机的3306端口
- -v /mydata/mysql/conf:/etc/mysql:将配置文件夹挂在到主机
- -v /mydata/mysql/log:/var/log/mysql:将日志文件夹挂载到主机
- -v /mydata/mysql/data:/var/lib/mysql/:将配置文件夹挂载到主机
-e MYSQL_ROOT_PASSWORD=123456:初始化root用户的密码
通过容器的mysql命令行工具连接
docker exec -it mysql mysql -uroot -p123456
设置远程访问
grant all privileges on . to 'root' @'%' identified by 'root'; flush privileges;
进入容器文件系统
docker exec -it mysql /bin/bash
docker pull redis:3.2
docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data -d redis:3.2 redis-server --appendonly yes
docker exec -it redis redis-cli
docker pull nginx:1.10
docker run -p 80:80 --name nginx \ -v /mydata/nginx/html:/usr/share/nginx/html \ -v /mydata/nginx/logs:/var/log/nginx \ -v /mydata/nginx/conf:/etc/nginx \ -d nginx:1.10
docker pull rabbitmq:management
docker run -d --name rabbitmq --publish 5671:5671 \ --publish 5672:5672 --publish 4369:4369 --publish 25672:25672 --publish 15671:15671 --publish 15672:15672 \ rabbitmq:management
docker pull elasticsearch:2.4
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \ -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \ -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \ -d elasticsearch:2.4
访问会返回版本信息:http://192.168.1.66:9200/
/usr/share/elasticsearch
测试:http://192.168.1.66:9200/_plugin/head/
下载中文分词器:https://github.com/medcl/elasticsearch-analysis-ik/releases?after=v5.6.4
上传后拷贝到容器中:docker container cp elasticsearch-analysis-ik-1.10.6.tar.gz elasticsearch:/usr/share/elasticsearch/plugins
进行解压操作:tar -xvf elasticsearch-analysis-ik-1.10.6.tar.gz
重新启动容器:docker restart elasticsearch
测试: POST:http://192.168.1.66:9200/_analyze JSON:{"analyzer":"ik","text":"联想是全球最大的笔记本厂商"}
docker pull mongo:3.2
docker run -p 27017:27017 --name mongo -v $PWD/db:/data/db -d mongo:3.2
docker exec -it mongo mongo
docker容器间进行连接才能互相访问
docker run -p 8080:8080 --name mall-admin \ --link mysql:db \ -d mall/mall-admin:0.0.1-SNAPSHOT
docker run -p 8081:8081 --name mall-search \ --link elasticsearch:es \ --link mysql:db \ -d mall/mall-search:0.0.1-SNAPSHOT
docker run -p 8085:8085 --name mall-portal \ --link mysql:db \ --link redis:redis \ --link mongo:mongo \ -d mall/mall-portal:0.0.1-SNAPSHOT
document/docker/docker-compose.yml
docker-compose up -d