- 安装yum-utils:
yum install -y yum-utils
device-mapper-persistent-data
lvm2 - 为yum源添加docker仓库位置:
yum-config-manager
--add-repo
https://download.docker.com/linux/centos/docker-ce.repo - 安装docker: yum install docker-ce
- 启动docker: systemctl start docker 注:常见命令见macro/spring-cloud-demo中的docker.md
- 安装上传下载插件: yum -y install lrzsz
- 下载地址:https://github.com/docker/compose/releases
- 安装地址:/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=root
-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=root:初始化root用户的密码
docker exec -it mysql mysql -uroot -proot
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
-d nginx:1.10
- 将容器内的配置文件拷贝到当前目录:docker container cp nginx:/etc/nginx .
- 修改文件名称:mv nginx conf
- 终止容器:docker stop nginx
- 执行命令删除原容器:docker rm $ContainerId
- 执行以下命令:
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
- 进入docker内部bash:docker exec -it elasticsearch /bin/bash
- 安装插件:plugin install mobz/elasticsearch-head
- 测试:http://192.168.1.66:9200/_plugin/head/
- 下载中文分词器:https://github.com/medcl/elasticsearch-analysis-ik/releases?after=v5.6.4的zip包,并解压后重新压缩为.tar.gz文件
- 上传后拷贝到容器中:docker container cp elasticsearch-analysis-ik-1.10.6.tar.gz elasticsearch:/usr/share/elasticsearch/plugins
- 进入容器压缩文件所在目录:docker exec -it elasticsearch /bin/bash
- 进行解压操作: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 /mydata/mongo/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