安装上传下载插件: yum -y install lrzsz
安装地址:/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用户的密码
通过容器的mysql命令行工具连接
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 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:6.4.0
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:6.4.0
访问会返回版本信息:http://192.168.1.66:9200/
/usr/share/elasticsearch
测试:http://192.168.1.66:9200/_plugin/head/
进入docker内部bash:docker exec -it elasticsearch /bin/bash
安装中文分词插件,执行以下命令:elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.2/elasticsearch-analysis-ik-6.2.2.zip
测试:
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 \ -v /etc/timezone:/etc/timezone \ -v /etc/localtime:/etc/localtime \ -v /mydata/app/admin/logs:/var/logs \ -d mall/mall-admin:1.0-SNAPSHOT
docker run -p 8081:8081 --name mall-search \ --link elasticsearch:es \ --link mysql:db \ -v /etc/timezone:/etc/timezone \ -v /etc/localtime:/etc/localtime \ -v /mydata/app/search/logs:/var/logs \ -d mall/mall-search:1.0-SNAPSHOT
docker run -p 8085:8085 --name mall-portal \ --link mysql:db \ --link redis:redis \ --link mongo:mongo \ -v /etc/timezone:/etc/timezone \ -v /etc/localtime:/etc/localtime \ -v /mydata/app/portal/logs:/var/logs \ -d mall/mall-portal:1.0-SNAPSHOT
document/docker/docker-compose.yml
docker-compose up -d